Clean up superfluous Netatmo API calls (#81095)

This commit is contained in:
Tobias Sauerwein 2022-10-27 20:42:16 +02:00 committed by GitHub
parent b490f47334
commit fa350b984a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View File

@ -252,7 +252,7 @@ class NetatmoDataHandler:
self, signal_name: str, update_callback: CALLBACK_TYPE | None self, signal_name: str, update_callback: CALLBACK_TYPE | None
) -> None: ) -> None:
"""Unsubscribe from publisher.""" """Unsubscribe from publisher."""
if update_callback in self.publisher[signal_name].subscriptions: if update_callback not in self.publisher[signal_name].subscriptions:
return return
self.publisher[signal_name].subscriptions.remove(update_callback) self.publisher[signal_name].subscriptions.remove(update_callback)
@ -288,6 +288,9 @@ class NetatmoDataHandler:
person.entity_id: person.pseudo for person in home.persons.values() person.entity_id: person.pseudo for person in home.persons.values()
} }
await self.unsubscribe(WEATHER, None)
await self.unsubscribe(AIR_CARE, None)
def setup_air_care(self) -> None: def setup_air_care(self) -> None:
"""Set up home coach/air care modules.""" """Set up home coach/air care modules."""
for module in self.account.modules.values(): for module in self.account.modules.values():

View File

@ -63,9 +63,11 @@ class NetatmoBase(Entity):
publisher["name"], signal_name, self.async_update_callback publisher["name"], signal_name, self.async_update_callback
) )
for sub in self.data_handler.publisher[signal_name].subscriptions: if any(
if sub is None: sub is None
await self.data_handler.unsubscribe(signal_name, None) for sub in self.data_handler.publisher[signal_name].subscriptions
):
await self.data_handler.unsubscribe(signal_name, None)
registry = dr.async_get(self.hass) registry = dr.async_get(self.hass)
if device := registry.async_get_device({(DOMAIN, self._id)}): if device := registry.async_get_device({(DOMAIN, self._id)}):

View File

@ -472,7 +472,7 @@ async def test_setup_component_no_devices(hass, config_entry):
assert await hass.config_entries.async_setup(config_entry.entry_id) assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
assert fake_post_hits == 9 assert fake_post_hits == 11
async def test_camera_image_raises_exception(hass, config_entry, requests_mock): async def test_camera_image_raises_exception(hass, config_entry, requests_mock):

View File

@ -110,7 +110,7 @@ async def test_setup_component_with_config(hass, config_entry):
await hass.async_block_till_done() await hass.async_block_till_done()
assert fake_post_hits == 8 assert fake_post_hits == 10
mock_impl.assert_called_once() mock_impl.assert_called_once()
mock_webhook.assert_called_once() mock_webhook.assert_called_once()