feat(bridge): MQTT bridge with Home Assistant auto-discovery

This commit is contained in:
2026-05-24 18:52:59 +03:00
parent e99616a135
commit c3837376f5
7 changed files with 282 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
package bridge
import (
"errors"
"strings"
)
type Config struct {
Broker string `yaml:"broker"`
Username string `yaml:"username"`
Password string `yaml:"password"`
ClientID string `yaml:"client_id"`
BaseTopic string `yaml:"base_topic"`
DiscoveryPrefix string `yaml:"discovery_prefix"`
}
func (c *Config) SetDefaults() {
if c.Broker == "" {
c.Broker = "tcp://localhost:1883"
}
if c.ClientID == "" {
c.ClientID = "ezcoo-usb-control"
}
if c.BaseTopic == "" {
c.BaseTopic = "ezcoo"
}
if c.DiscoveryPrefix == "" {
c.DiscoveryPrefix = "homeassistant"
}
c.BaseTopic = strings.TrimRight(c.BaseTopic, "/")
c.DiscoveryPrefix = strings.TrimRight(c.DiscoveryPrefix, "/")
}
func (c *Config) Validate() error {
if c.Broker == "" {
return errors.New("mqtt.broker is required")
}
if c.ClientID == "" {
return errors.New("mqtt.client_id is required")
}
return nil
}