Tapo: drop IP-address handling, use host string throughout (#29914)

This commit is contained in:
andig 2026-06-01 22:53:33 +02:00 • committed by GitHub
parent b40f06d48c
commit 6c6f051bde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 15 additions and 23 deletions

View file

@ -20,7 +20,7 @@ func init() {
func NewTapoFromConfig(other map[string]any) (api.Charger, error) {
var cc struct {
embed `mapstructure:",squash"`
URI string
Host string
User string
Password string
StandbyPower float64
@ -34,12 +34,12 @@ func NewTapoFromConfig(other map[string]any) (api.Charger, error) {
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
func NewTapo(embed embed, uri, user, password string, standbypower float64) (*Tapo, error) {
conn, err := tapo.NewConnection(uri, user, password)
func NewTapo(embed embed, host, user, password string, standbypower float64) (*Tapo, error) {
conn, err := tapo.NewConnection(host, user, password)
if err != nil {
return nil, err
}

2
go.mod
View file

@ -58,7 +58,7 @@ require (
github.com/hasura/go-graphql-client v0.16.0
github.com/holoplot/go-evdev v0.0.0-20250804134636-ab1d56a1fe83
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/jarcoal/httpmock v1.4.1
github.com/jeremywohl/flatten v1.0.1

4
go.sum
View file

@ -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/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/insomniacslk/tapo v1.0.2 h1:o2Bz941/Kp3LEjO5kvBbAE9Z4z9BcQMXRols3QkTnI0=
github.com/insomniacslk/tapo v1.0.2/go.mod h1:1wuMYu0+alZ4oE4BIzxAwQNveZgbb2tRqiIUwIe7SZE=
github.com/insomniacslk/tapo v1.1.0 h1:Z1s1EjtdVi1dWheW/gWEZPvppOPneHEUZ/Naw065vnM=
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/go.mod h1:Z4EVr4bVv9LZbbje9xyZEyOLpdCOmCvr5S9BJtrdTfw=
github.com/itchyny/gojq v0.12.19 h1:ttXA0XCLEMoaLOz5lSeFOZ6u6Q3QxmG46vfgI4O0DEs=

View file

@ -14,7 +14,7 @@ func init() {
// NewTapoFromConfig creates a tapo meter from generic config
func NewTapoFromConfig(other map[string]any) (api.Meter, error) {
var cc struct {
URI string
Host string
User string
Password string
}
@ -27,5 +27,5 @@ func NewTapoFromConfig(other map[string]any) (api.Meter, error) {
return nil, api.ErrMissingCredentials
}
return tapo.NewConnection(cc.URI, cc.User, cc.Password)
return tapo.NewConnection(cc.Host, cc.User, cc.Password)
}

View file

@ -2,8 +2,6 @@ package tapo
import (
"fmt"
"net/netip"
"net/url"
"strings"
"github.com/evcc-io/evcc/api"
@ -22,15 +20,9 @@ type Connection struct {
// NewConnection creates a new Tapo device connection.
// User is encoded by using MessageDigest of SHA1 which is afterwards B64 encoded.
// Password is directly B64 encoded.
func NewConnection(uri, user, password string) (*Connection, error) {
url, err := url.Parse(uri)
if err != nil {
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)
func NewConnection(host, user, password string) (*Connection, error) {
if host == "" {
return nil, fmt.Errorf("missing host")
}
if user == "" || password == "" {
@ -39,7 +31,7 @@ func NewConnection(uri, user, password string) (*Connection, error) {
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 {
return nil, fmt.Errorf("login failed: %w", err)
}

View file

@ -18,7 +18,7 @@ params:
- preset: switchsocket
render: |
type: tapo
uri: http://{{ .host }}
host: {{ .host }}
user: {{ .user }}
password: {{ .password }}
{{ include "switchsocket" . }}

View file

@ -18,6 +18,6 @@ params:
required: true
render: |
type: tapo
uri: http://{{ .host }}
host: {{ .host }}
user: {{ .user }}
password: {{ .password }}