Skip to content

Commit

Permalink
start mqtt after digitalstrom
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetancollaud committed Mar 30, 2022
1 parent 619534a commit cd710ef
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions digitalstrom_mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ func New(config *config.Config, digitalstrom *digitalstrom.Digitalstrom) *Digita
}
opts.OnConnectionLost = connectLostHandler
client := mqtt.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
log.Panic().
Err(token.Error()).
Str("url", config.Mqtt.MqttUrl).
Msg("Unable to connect to the mqtt broken")
}

inst.client = client
inst.digitalstrom = digitalstrom
Expand All @@ -85,6 +79,13 @@ func New(config *config.Config, digitalstrom *digitalstrom.Digitalstrom) *Digita
}

func (dm *DigitalstromMqtt) Start() {
if token := dm.client.Connect(); token.Wait() && token.Error() != nil {
log.Panic().
Err(token.Error()).
Str("url", dm.config.MqttUrl).
Msg("Unable to connect to the mqtt broken")
}

go dm.ListenSceneEvent(dm.digitalstrom.GetSceneEventsChannel())
go dm.ListenForDeviceState(dm.digitalstrom.GetDeviceChangeChannel())
go dm.ListenForCircuitValues(dm.digitalstrom.GetCircuitChangeChannel())
Expand Down

0 comments on commit cd710ef

Please sign in to comment.