chises / ha-oilfox

HomeAssistant Sensor for Oilfox
29 stars 4 forks source link

KeyError: 'No Error' #68

Closed t0bse closed 3 weeks ago

t0bse commented 3 months ago

Since a few days, i get this error in my log and no entites are available

Core 2024.7.2 Supervisor 2024.06.2 Operating System 12.3 Frontend 20240710.0

Oilfox 1.2.0

Error while setting up oilfox platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/oilfox/sensor.py", line 245, in async_setup_entry
    oilfox_sensor.set_state("No Error")
  File "/config/custom_components/oilfox/sensor.py", line 521, in set_state
    self._state = state + ":" + self.validation_error_mapping[state]
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'No Error'
t0bse commented 3 months ago

Debug:

2024-07-18 13:29:55.487 DEBUG (MainThread) [custom_components.oilfox.OilFox] Update Refresh and Access Token: ok [200]
2024-07-18 13:29:57.271 DEBUG (MainThread) [custom_components.oilfox.UpdateCoordinator] Finished fetching oilfox data in 1.914 seconds (success: True)
2024-07-18 13:29:57.271 INFO (MainThread) [custom_components.oilfox.sensor] OilFox: Setup User: tobias1337@gmail.com
2024-07-18 13:29:57.272 INFO (MainThread) [custom_components.oilfox.sensor] Load custom timeout value: 300
2024-07-18 13:29:57.272 INFO (MainThread) [custom_components.oilfox.sensor] Load custom poll interval: 59
2024-07-18 13:29:57.272 DEBUG (MainThread) [custom_components.oilfox.sensor] OilFox Coordinator Data Result: {'items': [{'hwid': 'ON123456', 'currentMeteringAt': '2024-07-18T08:02:29.033Z', 'nextMeteringAt': '2024-07-19T08:05:39.033Z', 'daysReach': 1214, 'batteryLevel': 'FULL', 'fillLevelPercent': 51, 'fillLevelQuantity': 3717, 'quantityUnit': 'L'}]}
2024-07-18 13:29:57.272 INFO (MainThread) [custom_components.oilfox.sensor] OilFox: Found Device in API: ON123456
2024-07-18 13:29:57.272 DEBUG (MainThread) [custom_components.oilfox.sensor] OilFox: Create Sensor fillLevelPercent for Device ON123456
2024-07-18 13:29:57.273 DEBUG (MainThread) [custom_components.oilfox.sensor] Prefill entity fillLevelPercent with 51
2024-07-18 13:29:57.273 DEBUG (MainThread) [custom_components.oilfox.sensor] Set new state 51 for sensor fillLevelPercent
2024-07-18 13:29:57.273 DEBUG (MainThread) [custom_components.oilfox.sensor] OilFox: Create Sensor fillLevelQuantity for Device ON123456
2024-07-18 13:29:57.274 DEBUG (MainThread) [custom_components.oilfox.sensor] Prefill entity fillLevelQuantity with 3717
2024-07-18 13:29:57.274 DEBUG (MainThread) [custom_components.oilfox.sensor] Set new state 3717 for sensor fillLevelQuantity
2024-07-18 13:29:57.274 DEBUG (MainThread) [custom_components.oilfox.sensor] OilFox: Create Sensor daysReach for Device ON123456
2024-07-18 13:29:57.274 DEBUG (MainThread) [custom_components.oilfox.sensor] Prefill entity daysReach with 1214
2024-07-18 13:29:57.274 DEBUG (MainThread) [custom_components.oilfox.sensor] Set new state 1214 for sensor daysReach
2024-07-18 13:29:57.274 DEBUG (MainThread) [custom_components.oilfox.sensor] OilFox: Create Sensor batteryLevel for Device ON123456
2024-07-18 13:29:57.274 DEBUG (MainThread) [custom_components.oilfox.sensor] Prefill entity batteryLevel with FULL
2024-07-18 13:29:57.276 DEBUG (MainThread) [custom_components.oilfox.sensor] Set new state 100 for sensor batteryLevel
2024-07-18 13:29:57.276 DEBUG (MainThread) [custom_components.oilfox.sensor] OilFox: Create Sensor validationError for Device ON123456
2024-07-18 13:29:57.276 DEBUG (MainThread) [custom_components.oilfox.sensor] Prefill entity validationError with "No Error"
2024-07-18 13:29:57.276 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up oilfox platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform
await asyncio.shield(awaitable)
File "/config/custom_components/oilfox/sensor.py", line 245, in async_setup_entry
oilfox_sensor.set_state("No Error")
File "/config/custom_components/oilfox/sensor.py", line 521, in set_state
self._state = state + ":" + self.validation_error_mapping[state]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
KeyError: 'No Error'
joe-pow commented 3 months ago

... same here

chises commented 3 months ago

Thank you for your report. Can you install the latest pre-release and check if the problem is gone? :)

t0bse commented 3 months ago

Thank you for your report. Can you install the latest pre-release and check if the problem is gone? :)

v.1.2.0-beta works for me 👍 thank you!

chises commented 3 months ago

@ChristophCaina fixed it accidentally in his PR, I don't think he was aware of that issue :D Thanks again for the PR. I will close this issue in a few days. If you see the issue again just post here :)

ChristophCaina commented 3 months ago

I also Had this Error mentioned in #64 and the Error was the reason I started to create the pr. But I didn't analyzed the root cause in particular - it was Part of rewriting the whole binary Sensor topic ^^

chises commented 3 weeks ago

Fixed by @ChristophCaina , thank you!