Fixing TypeError on missing battery data in battery.py#52
Open
loopy321 wants to merge 2 commits intovanstinator:mainfrom
Open
Fixing TypeError on missing battery data in battery.py#52loopy321 wants to merge 2 commits intovanstinator:mainfrom
loopy321 wants to merge 2 commits intovanstinator:mainfrom
Conversation
Getting errors when data missing like the following:
ERROR (MainThread) [homeassistant.components.melnor.coordinator] Unexpected error fetching Melnor Bluetooth data
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 392, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/melnor/coordinator.py", line 39, in _async_update_data
await self._device.fetch_state()
File "/usr/local/lib/python3.13/site-packages/melnor_bluetooth/device.py", line 349, in fetch_state
self._battery = parse_battery_value(some_bytes)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/melnor_bluetooth/utils/battery.py", line 4, in parse_battery_value
if (bytes[0] & 255 == 238) and (bytes[1] & 255 == 238):
~~~~~^^^
TypeError: 'NoneType' object is not subscriptable
Fix to step error messages like the following:
Unexpected error fetching Melnor Bluetooth data
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 392, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/melnor/coordinator.py", line 39, in _async_update_data
await self._device.fetch_state()
File "/usr/local/lib/python3.13/site-packages/melnor_bluetooth/device.py", line 353, in fetch_state
valve.update_state(bytes_array[some_bytes], uuids[i])
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/melnor_bluetooth/device.py", line 69, in update_state
self._is_watering = struct.unpack_from(">?", raw_bytes, offset)[0]
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'NoneType'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tested and works on my Home Assistant system.
Attempt to address missing data errors like the following: