From 89e15d9b575572491dc72243e53bb1327120e7a7 Mon Sep 17 00:00:00 2001 From: Alex X Date: Sat, 30 Dec 2023 13:04:53 +0300 Subject: [PATCH] Add support subtype for Tapo source #792 --- pkg/tapo/client.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/tapo/client.go b/pkg/tapo/client.go index 3ca9d9b3..5f1f2465 100644 --- a/pkg/tapo/client.go +++ b/pkg/tapo/client.go @@ -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 }