sebr / bhyve-home-assistant

Orbit BHyve custom component for Home Assistant
MIT License
251 stars 42 forks source link

Battery percent entity 'stuck' on one of my three devices #236

Closed AnthonyBe closed 4 months ago

AnthonyBe commented 4 months ago

Describe the bug I've been using the integration without issue for many months. After changing the batteries on one of my devices recently, I noticed that the battery percent reading in HA got 'stuck' on 90.83333333%

I've disabled and re-enabled the device in the integration config. Powered the BHyve device on and off numerous times. Nothing seems to rectify the issue. I have 2 other BHyve devices and they are reporting battery percent without issue. The BHyve device I'm seeing the issue with, is correctly reporting all other attirbutes, only battery percent is causing me an issue. The battery percent is showing correctly in the BHyve app (i.e. not a deice/Cloud/App/Platform issue) The battery percent is showing correctly in the attached integration diagnostic data! So I'm REALLY confused by this! It is as though the battery level sensor entity is 'stuck'! The only thing I haven't tried yet is deleting the integration and re-installing.

image image

Expected behaviour Correct battery percent values displayed

BHyve devices 1 x BHyve Hub 3 x BHyve tap timers

Device Diagnostics

config_entry-bhyve-5bc4b4819e8722eb2f3b99b8df98a730.json

In addition, I see this error in my HA log:

2024-04-22 09:33:02.043 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.back_garden_battery_level fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 951, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1268, in async_device_update
    await self.async_update()
  File "/config/custom_components/bhyve/sensor.py", line 155, in async_update
    await super().async_update()
  File "/config/custom_components/bhyve/__init__.py", line 247, in async_update
    self._on_ws_data(ws_event)
  File "/config/custom_components/bhyve/sensor.py", line 148, in _on_ws_data
    battery_level = self.parse_battery_level(event)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bhyve/sensor.py", line 175, in parse_battery_level
    battery_level = battery_data.get("percent", 0)
                    ^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'get'
sebr commented 4 months ago

I can see that your device is reporting both the battery percentage as well as the voltage level, which I haven't seen before:

   Battery: {'percent': 58, 'charging': False, 'mv': 2725, 'low_battery_at': '2023-12-14T11:49:00.000Z'}

Hopefully this means that the bhyve devices will always return the percentage and resolves other battery issues which have been seen in https://github.com/sebr/bhyve-home-assistant/issues/209

AnthonyBe commented 4 months ago

Just updated to 3.2.3 and it's resolved the issue. Thanks @sebr !

jhemak commented 4 months ago

Started seeing this today, for the first time, after updating:

WARNING (MainThread) [custom_components.bhyve.sensor] Unexpected battery data, returning 0: battery_status

sebr commented 4 months ago

@jhemak thanks - fixed in v3.2.4

jhemak commented 4 months ago

Thank you! Seems resolved for me now.