jason0x43 / hacs-hubitat

A Hubitat integration for Home Assistant
MIT License
191 stars 46 forks source link

RuntimeError: Attribute hass is None for #208

Closed syepes closed 1 year ago

syepes commented 1 year ago

I have started to observe the following exceptions from the post events received from HE:

Below is the full logs:

2023-04-13 23:27:51.932 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'last_observation_Forecast', 'value': '13/04/2023, 2:23 PM', 'displayName': 'OWM', 'deviceId': '1757', 'descriptionText': None, 'unit': None, 'type': None, 'data': None}
2023-04-13 23:27:51.932 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating last_observation_Forecast of 1757 to 13/04/2023, 2:23 PM (None)
2023-04-13 23:27:51.933 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback Hub._process_event({'content': {'data': None, 'descriptionText': None, 'deviceId': '1757', 'displayName': 'OWM', ...}})
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/hubitat/hubitatmaker/hub.py", line 327, in _process_event
    listener(evt)
  File "/config/custom_components/hubitat/hub.py", line 460, in handle_event
    listener(event)
  File "/config/custom_components/hubitat/device.py", line 175, in handle_event
    self.update_state()
  File "/config/custom_components/hubitat/device.py", line 180, in update_state
    self.async_schedule_update_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 721, in async_schedule_update_ha_state
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 561, in async_write_ha_state
    raise RuntimeError(f"Attribute hass is None for {self}")
RuntimeError: Attribute hass is None for <entity None=1007>

2023-04-13 23:27:38.914 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Received event: {'name': 'illuminated', 'value': '6,916 lx', 'displayName': 'OWM', 'deviceId': '1757', 'descriptionText': None, 'unit': None, 'type': None, 'data': None}
2023-04-13 23:27:38.914 DEBUG (MainThread) [custom_components.hubitat.hubitatmaker.hub] Updating illuminated of 1757 to 6,916 lx (None)
2023-04-13 23:27:38.915 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback Hub._process_event({'content': {'data': None, 'descriptionText': None, 'deviceId': '1757', 'displayName': 'OWM', ...}})
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/hubitat/hubitatmaker/hub.py", line 327, in _process_event
    listener(evt)
  File "/config/custom_components/hubitat/hub.py", line 460, in handle_event
    listener(event)
  File "/config/custom_components/hubitat/device.py", line 175, in handle_event
    self.update_state()
  File "/config/custom_components/hubitat/device.py", line 180, in update_state
    self.async_schedule_update_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 721, in async_schedule_update_ha_state
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 561, in async_write_ha_state
    raise RuntimeError(f"Attribute hass is None for {self}")
RuntimeError: Attribute hass is None for <entity None=1007>

Running under v0.9.1

jason0x43 commented 1 year ago

Is that happening for all device events, or just for certain devices?

syepes commented 1 year ago

Just for a specific virtual device that is using OWM (OpenWeatherMap), I have added another error.

I could this the driver but I don't know what is causing the issue. What field that is None or empty is causing the issue? I have looked at the code but cant seam to find it.

jason0x43 commented 1 year ago

What kind of entity is that virtual device being mapped to in the integration?

hass should be set on entities during the entity registration process. Each platform (e.g., alarm_control_panel) exposes an async_setup_entry function. HA calls that, passing it an entity registration function async_add_entities, to setup the integration's entities. That function, if you trace through it, eventually calls add_to_platform_start in core/homeassistant/helpers/entity.py, which sets the hass property on the entity.

syepes commented 1 year ago

This is the device in HA, it's curious that some values like the illuminated is giving the error but we can see it in the HA

CleanShot 2023-04-13 at 3 06 27 CleanShot 2023-04-13 at 3 07 24

jason0x43 commented 1 year ago

Hmmm...there doesn't appear to be an issue with the basic sensor entities. I setup a virtual illumination sensor, and it updates without throwing any errors.

What driver are you using in Hubitat for that device? I could try setting it up locally and see if I can reproduce the issue.

syepes commented 1 year ago

No worries, I'll give this a try also later.

This is the driver used, its the last version: https://raw.githubusercontent.com/HubitatCommunity/OpenWeatherMap-Alerts-Weather-Driver/master/OpenWeatherMap-Alerts%2520Weather%2520Driver.groovy

jason0x43 commented 1 year ago

I do get update errors with that weather driver. I think the issue may be with either or both of the wind sensors. If I disable them, hitting "refresh" in the weather device in Hubitat works without error. If I have the Windspeed sensor in HA, hitting "refresh" in the Hubitat weather device will generate the "hass is None" error in the HA log.

jason0x43 commented 1 year ago

This should be fixed in v0.9.4.