Add support subtype for Tapo source #792

This commit is contained in:
Alex X
2023-12-30 13:04:53 +03:00
parent 0d2292c311
commit 89e15d9b57
+21 -1
View File
@@ -39,6 +39,7 @@ type Client struct {
session1 string
session2 string
request string
recv int
send int
@@ -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
}
@@ -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
}