gaetancollaud / digitalstrom-mqtt

Bridge between digitalSTROM and MQTT
GNU Affero General Public License v3.0
23 stars 4 forks source link

Rungtime error: index out of range [0] #42

Closed sliemen closed 9 months ago

sliemen commented 9 months ago

I keep getting this error when I'm trying to create a connection between Digitalstrom and HomeAssisstant.

It only happens when I use the following parameters: HOME_ASSISTANT_DISCOVERY_ENABLED=true HOME_ASSISTANT_DISCOVERY_PREFIX=homeassistant

panic: runtime error: index out of range [0] with length
goroutine 1 [running]:
github.com/gaetancollaud/digitalstrom-mqtt/digitalstrom_mqtt. (*HomeAssistantMqtt).deviceToHomeAssistantDiscoveryMessage(0x4000011880, {{0x40000b06e8, 0x8}, {0x40000c41e0, 0x18}, {0x40000b6090, 0x22}, {0x36044e, 0x2}, {0x40000b0770, ...},
/home/runner/work/digitalstrom-mqtt/digitalstrom-mqtt/digitalstrom_mqtt/mqtt_homeassistant.go:109 +0xe00
github.com/gaetancollaud/digitalstrom-mqtt/digitalstrom_mqtt.(*HomeAssistantMqtt).publishDiscoveryMessages (0x4000011880)
/home/runner/work/digitalstrom-mqtt/digitalstrom-mqtt/digitalstrom_mqtt/mqtt_homeassistant.go:37 +0x238
github.com/gaetancollaud/digitalstrom-mqtt/digitalstrom_mqtt.(*HomeAssistantMqtt).Start(...)
/home/runner/work/digitalstrom-mqtt/digitalstrom-mqtt/digitalstrom_mqtt/mqtt_homeassistant.go:31
github.com/gaetancollaud/digitalstrom-mqtt/digitalstrom_mqtt.(*DigitalstromMqtt).Start(0x4000065aa0)
/home/runner/work/digitalstrom-mqtt/digitalstrom-mqtt/digitalstrom_mqtt/mqtt.go:95 +0x24c
main.main()
/home/runner/work/digitalstrom-matt/digitalstrom-mqtt/main.go:47 +0x40c
gaetancollaud commented 9 months ago

Thanks for the report. It seems that this piece of code is trying to access the first output channel of a light item, but apparently the light item has no output, which is weird. Can you list the type of light devices you own please (ex GE-KM200).

sliemen commented 9 months ago

I'm using Philips Hue lights that are connected to Digitalstrom in a test setup. See following output:



2023-11-29T11:00:48Z DBG Circuits loaded circuits="[{\"name\":\"Woonkamer\",\"Dsid\":\"3504175fe00000100000162f\",\"HwName\":\"dSM11\",\"HasMetering\":true,\"IsValid\":true},{\"name\":\"Keuken\",\"Dsid\":\"3504175fe0000010000015 2023-11-29T11:00:48Z DBG Devices loaded devices="[{\"name\":\"GU10 LED\",\"Dsid\":\"3504175fe000000000019915\",\"Dsuid\":\"3504175fe0000000000000000001991500\",\"DeviceType\":\"GE\",\"HwInfo\":\"GE-KM200\",\"MeterDsid\":\"350417
de\",\"HwName\":\"dSM11\",\"HasMetering\":true,\"IsValid\":true}]"
5fe00000100000162f\",\"MeterDsuid\":\"3504175fe0000000000000100000162f00\",\"MeterName\":\"Woonkamer\",\"ZoneId\":5679,\"OutputChannels\":null,\"Groups\":[1],\"Values\":{},\"Properties\":{\"Dimmable\":true}},{\"name\":\"Lichtsch akelaar woning\",\"Dsid\":\"3504175fe000000000031735\",\"Dsuid\":\"3504175fe0000000000000000003173500\",\"DeviceType\":\"GE\",\"HwInfo\":\"GE-TKM210\",\"MeterDsid\":\"3504175fe00000100000162f\",\"MeterDsuid\":\"3504175fe00000000
00000100000162f00\",\"MeterName\":\"Woonkamer\",\"ZoneId\":5679,\"OutputChannels\":null,\"Groups\":[1],\"Values\":{},\"Properties\":{\"Dimmable\":false}},{\"name\":\"Bel knop\",\"Dsid\":\"3504175fe00000000000a0bd\",\"Dsuid\":\"3
504175fe0000000000000000000a0bd00\",\"DeviceType\":\"Unknown\",\"HwInfo\":\"GN-TKM210\",\"MeterDsid\":\"3504175fe0000010000015de\",\"MeterDsuid\":\"3504175fe000000000000010000015de00\",\"MeterName\":\"Keuken\",\"ZoneId\":1,\"Out
putChannels\":null,\"Groups\":[7],\"Values\":{},\"Properties\":{\"Dimmable\":false}},{\"name\":\"Huisverlaten knop\",\"Dsid\":\"3504175fe00000000000a5fb\",\"Dsuid\":\"3504175fe0000000000000000000a5fb00\",\"DeviceType\":\"Unknown
\",\"HwInfo\":\"GN-TKM200\",\"MeterDsid\":\"3504175fe0000010000015de\",
\"MeterDsuid\":\"3504175fe000000000000010000015de00\",\"MeterName\":\"Keuken\",\"ZoneId\":1,\"OutputChannels\":null,\"Groups\":[7],\"Values\":{},\"Properties
\":{\"Dimmable\":false}},{\"name\":\"E27 Halogeen\",\"Dsid\":\"3504175fe0000000000193e3\",\"Dsuid\":\"3504175fe000000000000000000193e300\",\"DeviceType\":\"GE\",\"HwInfo\":\"GE-KM200\",\"MeterDsid\":\"3504175fe0000010000015de\",
\"MeterDsuid\":\"3504175fe000000000000010000015de00\",\"MeterName\":\"Keuken\",\"ZoneId\":5598,\"OutputChannels\":null,\"Groups\":[1],\"Values\":{},\"Properties\":{\"Dimmable\":true}},{\"name\":\"Lichtschakelaar keuken\",\"Dsid\
":\"3504175fe0000000000318fc\",\"Dsuid\":\"3504175fe000000000000000000318fc00\",\"DeviceType\":\"GE\",\"HwInfo\":\"GE-TKM210\",\"MeterDsid\":\"3504175fe0000010000015de\",\"MeterDsuid\":\"3504175fe000000000000010000015de00\",\"Me
terName\":\"Keuken\",\"ZoneId\":5598,\"OutputChannels\":null,\"Groups\":[1],\"Values\":{},\"Properties\":{\"Dimmable\":true}},{\"name\":\"Knubbig Blau\",\"Dsid\":\"3504175fe00000000000f348\",\"Dsuid\":\"3504175fe0000000000000000 000f34800\",\"DeviceType\":\"Unknown\", \"HwInfo\":\"Knubbig Blau 2-Wege Taster\",\"MeterDsid\":\"3504175fe00000100000162f\",\"MeterDsuid\":\"3504175fe0000000000000100000162f00\",\"MeterName\":\"Woonkamer\",\"ZoneId\":5679,\"Outp 2023-11-29T11:00:48Z INF Refreshing all devices size=7
utChannels\":null,\"Groups\":[1],\"Values\":{},\"Properties\":{\"Dimmable\":false}}]"
2023-11-29T11:00:48Z DBG Updating device device="GU10 LED"
2023-11-29T11:00:48Z DBG Updating device 2023-11-29T11:00:48Z DBG Updating device 2023-11-29T11:00:48Z DBG Updating device 2023-11-29T11:00:48Z DBG Updating device 2023-11-29T11:00:48Z INF Updating server 2023-11-29T11:00:48Z DBG Updating device 2023-11-29T11:00:48Z DBG Updating device 2023-11-29T11:00:48Z INF MQTT Connected
device="Lichtschakelaar woning"
device="Bel knop"
device="Huisverlaten knop" device="E27 Halogeen"
status topic status-online topic-digitalstrom/server/state device="Lichtschakelaar keuken" device="Knubbig Blau"
gaetancollaud commented 9 months ago

Thanks a lot, that helps ! I can see "OutputChannels\":null for the Hue. I will try to come up with a patch this week or the next one. I will post here when I realease it.

sliemen commented 9 months ago

Thanks!

gaetancollaud commented 9 months ago

Release 1.6.7 is out. I don't use Home Assistant, so I hope it helps I wasn't able to properly test.