seanrees / prometheus-dyson

Prometheus client for DysonLink fans (Pure Hot+Cool)
MIT License
13 stars 9 forks source link

ValueError: 'IDLE' is not in list #8

Closed Scaredycrow closed 3 years ago

Scaredycrow commented 3 years ago

Me Again :-)

Noticed an issue that present at a repeatable time of day, relating to the schedule feature of the V2 device.

Error:

Jan 11 08:00:11 ubuntuvm python3[1096]: Exception in thread Thread-2:
Jan 11 08:00:11 ubuntuvm python3[1096]: Traceback (most recent call last):
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.run()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/lib/python3.8/threading.py", line 870, in run
Jan 11 08:00:11 ubuntuvm python3[1096]:     self._target(*self._args, **self._kwargs)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.loop_forever(retry_first_connection=True)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self.loop(timeout, max_packets)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1181, in loop
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self.loop_read(max_packets)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self._packet_read()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
Jan 11 08:00:11 ubuntuvm python3[1096]:     rc = self._packet_handle()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 2936, in _packet_handle
Jan 11 08:00:11 ubuntuvm python3[1096]:     return self._handle_publish()
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 3216, in _handle_publish
Jan 11 08:00:11 ubuntuvm python3[1096]:     self._handle_on_message(message)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/paho/mqtt/client.py", line 3444, in _handle_on_message
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.on_message(self, self._userdata, message)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/libpurecool/dyson_pure_cool_link.py", line 100, in on_message
Jan 11 08:00:11 ubuntuvm python3[1096]:     function(device_msg)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/opt/prometheus-dyson/bin/main.py", line 125, in update
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.updateFanStateV2(name, serial, message)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/opt/prometheus-dyson/bin/main.py", line 205, in updateFanStateV2
Jan 11 08:00:11 ubuntuvm python3[1096]:     self.oscillation.labels(name=name, serial=serial).state(message.oscillation_status)
Jan 11 08:00:11 ubuntuvm python3[1096]:   File "/usr/local/lib/python3.8/dist-packages/prometheus_client/metrics.py", line 661, in state
Jan 11 08:00:11 ubuntuvm python3[1096]:     self._value = self._states.index(state)
Jan 11 08:00:11 ubuntuvm python3[1096]: ValueError: 'IDLE' is not in list
seanrees commented 3 years ago

Thanks again! This was really helpful -- when I was putting together the V2 support, I didn't understand the difference between "oscillation" and "oscillation_state." This pointed me in the right direction.

I pushed a fix for this to the main branch. It looks from this stack trace that you're still on the experimental branch, so I'd suggest switching over :-)

V2 devices emit two different states:

dyson_oscillation_mode reflects the intention, which is consistent with the other _mode metrics. The state is reflected in dyson_oscillation_state which is also consistent with the other _state metrics -- in case that makes a difference to your dashboard.

Scaredycrow commented 3 years ago

Great. I'll test this in the next day or so. This is making it's way out of my testing vm's and into a "prod" state of my home lab.

Scaredycrow commented 3 years ago

Update applied. I will confirm efficacy in the next 24 hours. I've also converted the existing Grafana template to use the oscillation_state replacing oscillation_mode to report actual state, rather than the intended.

seanrees commented 3 years ago

Going to close this out -- please let me know if you run into issues :)