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

@ -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)
}