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 }