Tapo: drop IP-address handling, use host string throughout (#29914)
This commit is contained in:
parent
b40f06d48c
commit
6c6f051bde
7 changed files with 15 additions and 23 deletions
|
|
@ -20,7 +20,7 @@ func init() {
|
||||||
func NewTapoFromConfig(other map[string]any) (api.Charger, error) {
|
func NewTapoFromConfig(other map[string]any) (api.Charger, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
embed `mapstructure:",squash"`
|
embed `mapstructure:",squash"`
|
||||||
URI string
|
Host string
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
StandbyPower float64
|
StandbyPower float64
|
||||||
|
|
@ -34,12 +34,12 @@ func NewTapoFromConfig(other map[string]any) (api.Charger, error) {
|
||||||
return nil, api.ErrMissingCredentials
|
return nil, api.ErrMissingCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewTapo(cc.embed, cc.URI, cc.User, cc.Password, cc.StandbyPower)
|
return NewTapo(cc.embed, cc.Host, cc.User, cc.Password, cc.StandbyPower)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTapo creates Tapo charger
|
// NewTapo creates Tapo charger
|
||||||
func NewTapo(embed embed, uri, user, password string, standbypower float64) (*Tapo, error) {
|
func NewTapo(embed embed, host, user, password string, standbypower float64) (*Tapo, error) {
|
||||||
conn, err := tapo.NewConnection(uri, user, password)
|
conn, err := tapo.NewConnection(host, user, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -58,7 +58,7 @@ require (
|
||||||
github.com/hasura/go-graphql-client v0.16.0
|
github.com/hasura/go-graphql-client v0.16.0
|
||||||
github.com/holoplot/go-evdev v0.0.0-20250804134636-ab1d56a1fe83
|
github.com/holoplot/go-evdev v0.0.0-20250804134636-ab1d56a1fe83
|
||||||
github.com/influxdata/influxdb-client-go/v2 v2.14.0
|
github.com/influxdata/influxdb-client-go/v2 v2.14.0
|
||||||
github.com/insomniacslk/tapo v1.0.2
|
github.com/insomniacslk/tapo v1.1.0
|
||||||
github.com/itchyny/gojq v0.12.19
|
github.com/itchyny/gojq v0.12.19
|
||||||
github.com/jarcoal/httpmock v1.4.1
|
github.com/jarcoal/httpmock v1.4.1
|
||||||
github.com/jeremywohl/flatten v1.0.1
|
github.com/jeremywohl/flatten v1.0.1
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -409,8 +409,8 @@ github.com/influxdata/influxdb-client-go/v2 v2.14.0/go.mod h1:Ahpm3QXKMJslpXl3If
|
||||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||||
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf h1:7JTmneyiNEwVBOHSjoMxiWAqB992atOeepeFYegn5RU=
|
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf h1:7JTmneyiNEwVBOHSjoMxiWAqB992atOeepeFYegn5RU=
|
||||||
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
|
github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
|
||||||
github.com/insomniacslk/tapo v1.0.2 h1:o2Bz941/Kp3LEjO5kvBbAE9Z4z9BcQMXRols3QkTnI0=
|
github.com/insomniacslk/tapo v1.1.0 h1:Z1s1EjtdVi1dWheW/gWEZPvppOPneHEUZ/Naw065vnM=
|
||||||
github.com/insomniacslk/tapo v1.0.2/go.mod h1:1wuMYu0+alZ4oE4BIzxAwQNveZgbb2tRqiIUwIe7SZE=
|
github.com/insomniacslk/tapo v1.1.0/go.mod h1:1wuMYu0+alZ4oE4BIzxAwQNveZgbb2tRqiIUwIe7SZE=
|
||||||
github.com/insomniacslk/xjson v0.0.0-20231023101448-2249e546a131 h1:bVGPuMhjgFtxVdQGfYnFq+EnCqArOAjLNciow/nArwE=
|
github.com/insomniacslk/xjson v0.0.0-20231023101448-2249e546a131 h1:bVGPuMhjgFtxVdQGfYnFq+EnCqArOAjLNciow/nArwE=
|
||||||
github.com/insomniacslk/xjson v0.0.0-20231023101448-2249e546a131/go.mod h1:Z4EVr4bVv9LZbbje9xyZEyOLpdCOmCvr5S9BJtrdTfw=
|
github.com/insomniacslk/xjson v0.0.0-20231023101448-2249e546a131/go.mod h1:Z4EVr4bVv9LZbbje9xyZEyOLpdCOmCvr5S9BJtrdTfw=
|
||||||
github.com/itchyny/gojq v0.12.19 h1:ttXA0XCLEMoaLOz5lSeFOZ6u6Q3QxmG46vfgI4O0DEs=
|
github.com/itchyny/gojq v0.12.19 h1:ttXA0XCLEMoaLOz5lSeFOZ6u6Q3QxmG46vfgI4O0DEs=
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ func init() {
|
||||||
// NewTapoFromConfig creates a tapo meter from generic config
|
// NewTapoFromConfig creates a tapo meter from generic config
|
||||||
func NewTapoFromConfig(other map[string]any) (api.Meter, error) {
|
func NewTapoFromConfig(other map[string]any) (api.Meter, error) {
|
||||||
var cc struct {
|
var cc struct {
|
||||||
URI string
|
Host string
|
||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
@ -27,5 +27,5 @@ func NewTapoFromConfig(other map[string]any) (api.Meter, error) {
|
||||||
return nil, api.ErrMissingCredentials
|
return nil, api.ErrMissingCredentials
|
||||||
}
|
}
|
||||||
|
|
||||||
return tapo.NewConnection(cc.URI, cc.User, cc.Password)
|
return tapo.NewConnection(cc.Host, cc.User, cc.Password)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ package tapo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/evcc-io/evcc/api"
|
"github.com/evcc-io/evcc/api"
|
||||||
|
|
@ -22,15 +20,9 @@ type Connection struct {
|
||||||
// NewConnection creates a new Tapo device connection.
|
// NewConnection creates a new Tapo device connection.
|
||||||
// User is encoded by using MessageDigest of SHA1 which is afterwards B64 encoded.
|
// User is encoded by using MessageDigest of SHA1 which is afterwards B64 encoded.
|
||||||
// Password is directly B64 encoded.
|
// Password is directly B64 encoded.
|
||||||
func NewConnection(uri, user, password string) (*Connection, error) {
|
func NewConnection(host, user, password string) (*Connection, error) {
|
||||||
url, err := url.Parse(uri)
|
if host == "" {
|
||||||
if err != nil {
|
return nil, fmt.Errorf("missing host")
|
||||||
return nil, fmt.Errorf("invalid url: %s", uri)
|
|
||||||
}
|
|
||||||
|
|
||||||
addr, err := netip.ParseAddr(url.Hostname())
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid ip address: %s", uri)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if user == "" || password == "" {
|
if user == "" || password == "" {
|
||||||
|
|
@ -39,7 +31,7 @@ func NewConnection(uri, user, password string) (*Connection, error) {
|
||||||
|
|
||||||
log := util.NewLogger("tapo").Redact(user, password)
|
log := util.NewLogger("tapo").Redact(user, password)
|
||||||
|
|
||||||
plug := tapo.NewPlug(addr, nil)
|
plug := tapo.NewPlug(host, nil)
|
||||||
if err := plug.Handshake(user, password); err != nil {
|
if err := plug.Handshake(user, password); err != nil {
|
||||||
return nil, fmt.Errorf("login failed: %w", err)
|
return nil, fmt.Errorf("login failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ params:
|
||||||
- preset: switchsocket
|
- preset: switchsocket
|
||||||
render: |
|
render: |
|
||||||
type: tapo
|
type: tapo
|
||||||
uri: http://{{ .host }}
|
host: {{ .host }}
|
||||||
user: {{ .user }}
|
user: {{ .user }}
|
||||||
password: {{ .password }}
|
password: {{ .password }}
|
||||||
{{ include "switchsocket" . }}
|
{{ include "switchsocket" . }}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,6 @@ params:
|
||||||
required: true
|
required: true
|
||||||
render: |
|
render: |
|
||||||
type: tapo
|
type: tapo
|
||||||
uri: http://{{ .host }}
|
host: {{ .host }}
|
||||||
user: {{ .user }}
|
user: {{ .user }}
|
||||||
password: {{ .password }}
|
password: {{ .password }}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue