Skip to content

Commit

Permalink
Add support subtype for Tapo source #792
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Dec 30, 2023
1 parent 0d2292c commit 89e15d9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/tapo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Client struct {

session1 string
session2 string
request string

recv int
send int
Expand Down Expand Up @@ -90,6 +91,25 @@ func (c *Client) newConn() (net.Conn, error) {
c.newDectypter(res)
}

query := u.Query()
channel := query.Get("channel")
if channel == "" {
channel = "0"
}

subtype := query.Get("subtype")
switch subtype {
case "", "0":
subtype = "HD"
case "1":
subtype = "VGA"
}

c.request = fmt.Sprintf(
`{"params":{"preview":{"audio":["default"],"channels":[%s],"resolutions":["%s"]},"method":"get"},"seq":1,"type":"request"}`,
channel, subtype,
)

return conn, nil
}

Expand Down Expand Up @@ -131,7 +151,7 @@ func (c *Client) SetupStream() (err error) {
}

// audio: default, disable, enable
c.session1, err = c.Request(c.conn1, []byte(`{"params":{"preview":{"audio":["default"],"channels":[0],"resolutions":["HD"]},"method":"get"},"seq":1,"type":"request"}`))
c.session1, err = c.Request(c.conn1, []byte(c.request))
return
}

Expand Down

0 comments on commit 89e15d9

Please sign in to comment.