zigpy / zha

Zigbee Home Automation
Apache License 2.0
21 stars 19 forks source link

Add guard to global updater #174

Closed dmulcahey closed 1 month ago

dmulcahey commented 1 month ago

This PR fixes an exception I ran into when building out the HA side of PR: https://github.com/zigpy/zha/pull/93

Traceback (most recent call last):
  File "/Users/dmulcahey/development/homeassistant/home-assistant/homeassistant/config_entries.py", line 819, in async_unload
    result = await component.async_unload_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dmulcahey/development/homeassistant/home-assistant/homeassistant/components/zha/__init__.py", line 234, in async_unload_entry
    await ha_zha_data.gateway_proxy.shutdown()
  File "/Users/dmulcahey/development/homeassistant/home-assistant/homeassistant/components/zha/helpers.py", line 753, in shutdown
    await self.gateway.shutdown()
  File "/Users/dmulcahey/development/homeassistant/home-assistant/venv/lib/python3.12/site-packages/zha/application/gateway.py", line 741, in shutdown
    await device.on_remove()
  File "/Users/dmulcahey/development/homeassistant/home-assistant/venv/lib/python3.12/site-packages/zha/zigbee/device.py", line 773, in on_remove
    await platform_entity.on_remove()
  File "/Users/dmulcahey/development/homeassistant/home-assistant/venv/lib/python3.12/site-packages/zha/application/platforms/sensor/__init__.py", line 467, in on_remove
    self._device.gateway.global_updater.remove_update_listener(self.update)
  File "/Users/dmulcahey/development/homeassistant/home-assistant/venv/lib/python3.12/site-packages/zha/application/helpers.py", line 405, in remove_update_listener
    self._update_listeners.remove(listener)
ValueError: list.remove(x): x not in list
codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.79%. Comparing base (2f06f00) to head (5d62314). Report is 1 commits behind head on dev.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #174 +/- ## ======================================= Coverage 95.79% 95.79% ======================================= Files 61 61 Lines 9319 9323 +4 ======================================= + Hits 8927 8931 +4 Misses 392 392 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.