Clean up superfluous Netatmo API calls (#81095)
This commit is contained in:
parent
b490f47334
commit
fa350b984a
4 changed files with 11 additions and 6 deletions
|
@ -252,7 +252,7 @@ class NetatmoDataHandler:
|
|||
self, signal_name: str, update_callback: CALLBACK_TYPE | None
|
||||
) -> None:
|
||||
"""Unsubscribe from publisher."""
|
||||
if update_callback in self.publisher[signal_name].subscriptions:
|
||||
if update_callback not in self.publisher[signal_name].subscriptions:
|
||||
return
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
await self.unsubscribe(WEATHER, None)
|
||||
await self.unsubscribe(AIR_CARE, None)
|
||||
|
||||
def setup_air_care(self) -> None:
|
||||
"""Set up home coach/air care modules."""
|
||||
for module in self.account.modules.values():
|
||||
|
|
|
@ -63,9 +63,11 @@ class NetatmoBase(Entity):
|
|||
publisher["name"], signal_name, self.async_update_callback
|
||||
)
|
||||
|
||||
for sub in self.data_handler.publisher[signal_name].subscriptions:
|
||||
if sub is None:
|
||||
await self.data_handler.unsubscribe(signal_name, None)
|
||||
if any(
|
||||
sub is 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)
|
||||
if device := registry.async_get_device({(DOMAIN, self._id)}):
|
||||
|
|
|
@ -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)
|
||||
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):
|
||||
|
|
|
@ -110,7 +110,7 @@ async def test_setup_component_with_config(hass, config_entry):
|
|||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert fake_post_hits == 8
|
||||
assert fake_post_hits == 10
|
||||
mock_impl.assert_called_once()
|
||||
mock_webhook.assert_called_once()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue