home_assistant_thethingsnetwork
home_assistant_thethingsnetwork copied to clipboard
hass is None
After every fetch of data from TTN, there is this error in the log:
2024-03-04 07:56:04.126 ERROR (MainThread) [custom_components.thethingsnetwork] Unexpected error fetching The Things Network data: Attribute hass is None for <entity unknown.unknown=unknown>
Traceback (most recent call last):
File "/home/nuc/.local/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 313, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nuc/.local/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 269, in _async_update_data
return await self.update_method()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/nuc/.homeassistant/custom_components/thethingsnetwork/TTN_client.py", line 153, in fetch_data_from_ttn
await self.__fetch_data_from_ttn()
File "/home/nuc/.homeassistant/custom_components/thethingsnetwork/TTN_client.py", line 272, in __fetch_data_from_ttn
await process(field_id, value)
File "/home/nuc/.homeassistant/custom_components/thethingsnetwork/TTN_client.py", line 243, in process
await self.__entities[unique_id].async_set_state(value)
File "/home/nuc/.homeassistant/custom_components/thethingsnetwork/TTN_client.py", line 567, in async_set_state
await self.async_update_ha_state()
File "/home/nuc/.local/lib/python3.11/site-packages/homeassistant/helpers/entity.py", line 932, in async_update_ha_state
raise RuntimeError(f"Attribute hass is None for {self}")
RuntimeError: Attribute hass is None for <entity unknown.unknown=unknown>
The sensor data is there, it is not missing.
I am not getting this error but I get
WARNING (MainThread) [homeassistant.helpers.entity] Entity sensor.soil_v2_26_raw (<class 'custom_components.thethingsnetwork.TTN_client.TtnDataSensor'>) is using self.async_update_ha_state(), without enabling force_update. Instead it should use self.async_write_ha_state(), please create a bug report at https://github.com/angelnu/home_assistant_thethingsnetwork/issues
This was reported with #17
I will look at fixing this one and see if that helps with your case as well.
I just found that I have this error only with 2 devices from 7. Maybe it is because I renamed a device or a sensor?
I changed the code in TTN_client.py and this seems to fix it:
async def async_set_state(self, value):
if self.hass: # jms
self._state = value
await self.async_update_ha_state()
Thanks @martin3000 - I added the deprecation fix and your check at https://github.com/angelnu/home_assistant_thethingsnetwork/commit/ccf6fb6e1086817d5c00ca86d1bc06839e056c7a
Please let me know if that fixes the issue
Thank you, its ok now