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