Skip to content
Snippets Groups Projects
Commit 6067145c authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Refactoring in progress

ignoredTopics are now in Config ;)
It's time to remove the Gateway singleton ?
parent 052ca2ea
No related branches found
No related tags found
No related merge requests found
package main package main
import ( import (
"fmt"
"gitlab.imt-atlantique.fr/xaal/code/go/core/uuid" "gitlab.imt-atlantique.fr/xaal/code/go/core/uuid"
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal" "gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
) )
var ( var (
mqttTopic = "zigbee2mqtt" mqttTopic = "zigbee2mqtt"
mqttClientID = "z2m-" + uuid.New().String() mqttClientID = "z2m-" + uuid.New().String()
ignoredTopics = []string{
"bridge/groups",
"bridge/definitions",
"bridge/extensions",
"bridge/info",
"bridge/state",
"bridge/logging",
"bridge/config",
}
) )
type Config struct { type Config struct {
brokerHost string brokerHost string
topic string topic string
logLevel string logLevel string
brokerPort int ignoredTopics []string
baseAddr uuid.UUID brokerPort int
baseAddr uuid.UUID
} }
func parseConfig() (*Config, error) { func parseConfig() (*Config, error) {
...@@ -64,5 +76,8 @@ func parseConfig() (*Config, error) { ...@@ -64,5 +76,8 @@ func parseConfig() (*Config, error) {
} }
config.baseAddr = baseAddr config.baseAddr = baseAddr
} }
for _, topic := range ignoredTopics {
config.ignoredTopics = append(config.ignoredTopics, fmt.Sprintf("%s/%s", config.topic, topic))
}
return &config, nil return &config, nil
} }
...@@ -60,10 +60,9 @@ func (gw *Gateway) GetZDeviceByTopic(topic string) *Z2MDevice { ...@@ -60,10 +60,9 @@ func (gw *Gateway) GetZDeviceByTopic(topic string) *Z2MDevice {
// Else it will find the device with the topic and call the mqttDeviceHandler // Else it will find the device with the topic and call the mqttDeviceHandler
func (gw *Gateway) mqttPublishHander(client MQTT.Client, msg MQTT.Message) { func (gw *Gateway) mqttPublishHander(client MQTT.Client, msg MQTT.Message) {
// we ignore some topics // we ignore some topics
if slices.Contains(ignoredTopics, msg.Topic()) { if slices.Contains(gw.config.ignoredTopics, msg.Topic()) {
return return
} }
// slog.Debug("Received message on", "topic", msg.Topic())
// Is it devices definitions ? // Is it devices definitions ?
if msg.Topic() == gw.config.topic+"/bridge/devices" { if msg.Topic() == gw.config.topic+"/bridge/devices" {
gw.jsonParseDevices(msg.Payload()) gw.jsonParseDevices(msg.Payload())
......
...@@ -23,16 +23,6 @@ type ( ...@@ -23,16 +23,6 @@ type (
AccessLevel int AccessLevel int
) )
var ignoredTopics = []string{
mqttTopic + "/bridge/groups",
mqttTopic + "/bridge/definitions",
mqttTopic + "/bridge/extensions",
mqttTopic + "/bridge/info",
mqttTopic + "/bridge/state",
mqttTopic + "/bridge/logging",
mqttTopic + "/bridge/config",
}
// JSON structures for the z2m device from /bridge/devices // JSON structures for the z2m device from /bridge/devices
type Z2MDevice struct { type Z2MDevice struct {
Definition struct { Definition struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment