From 6e8e14fbe219af0071a4034d8c591f09e8a98281 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 19 Jan 2024 00:14:49 +0100 Subject: [PATCH] Improve august typing (3) (#108329) --- homeassistant/components/august/__init__.py | 12 ++++++------ homeassistant/components/august/camera.py | 2 +- homeassistant/components/august/entity.py | 2 +- homeassistant/components/august/lock.py | 2 +- homeassistant/components/august/sensor.py | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/august/__init__.py b/homeassistant/components/august/__init__.py index 6c625011ee2..eb54a488831 100644 --- a/homeassistant/components/august/__init__.py +++ b/homeassistant/components/august/__init__.py @@ -140,7 +140,7 @@ class AugustData(AugustSubscriberMixin): self._config_entry = config_entry self._hass = hass self._august_gateway = august_gateway - self.activity_stream: ActivityStream | None = None + self.activity_stream: ActivityStream = None # type: ignore[assignment] self._api = august_gateway.api self._device_detail_by_id: dict[str, LockDetail | DoorbellDetail] = {} self._doorbells_by_id: dict[str, Doorbell] = {} @@ -153,7 +153,7 @@ class AugustData(AugustSubscriberMixin): """Brand of the device.""" return self._config_entry.data.get(CONF_BRAND, DEFAULT_BRAND) - async def async_setup(self): + async def async_setup(self) -> None: """Async setup of august device data and activities.""" token = self._august_gateway.access_token # This used to be a gather but it was less reliable with august's recent api changes. @@ -248,16 +248,16 @@ class AugustData(AugustSubscriberMixin): device = self.get_device_detail(device_id) activities = activities_from_pubnub_message(device, date_time, message) activity_stream = self.activity_stream - assert activity_stream is not None if activities: activity_stream.async_process_newer_device_activities(activities) self.async_signal_device_id_update(device.device_id) activity_stream.async_schedule_house_id_refresh(device.house_id) @callback - def async_stop(self): + def async_stop(self) -> None: """Stop the subscriptions.""" - self._pubnub_unsub() + if self._pubnub_unsub: + self._pubnub_unsub() self.activity_stream.async_stop() @property @@ -303,7 +303,7 @@ class AugustData(AugustSubscriberMixin): exc_info=err, ) - async def _async_refresh_device_detail_by_id(self, device_id): + async def _async_refresh_device_detail_by_id(self, device_id: str) -> None: if device_id in self._locks_by_id: if self.activity_stream and self.activity_stream.pubnub.connected: saved_attrs = _save_live_attrs(self._device_detail_by_id[device_id]) diff --git a/homeassistant/components/august/camera.py b/homeassistant/components/august/camera.py index 904ef316e5b..17c9f91c566 100644 --- a/homeassistant/components/august/camera.py +++ b/homeassistant/components/august/camera.py @@ -63,7 +63,7 @@ class AugustCamera(AugustEntityMixin, Camera): return self._detail.model @callback - def _update_from_data(self): + def _update_from_data(self) -> None: """Get the latest state of the sensor.""" doorbell_activity = self._data.activity_stream.get_latest_device_activity( self._device_id, diff --git a/homeassistant/components/august/entity.py b/homeassistant/components/august/entity.py index 787b99c34ac..ce32157e1e4 100644 --- a/homeassistant/components/august/entity.py +++ b/homeassistant/components/august/entity.py @@ -63,7 +63,7 @@ class AugustEntityMixin(Entity): def _update_from_data(self) -> None: """Update the entity state from the data object.""" - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Subscribe to updates.""" self.async_on_remove( self._data.async_subscribe_device_id( diff --git a/homeassistant/components/august/lock.py b/homeassistant/components/august/lock.py index 31a4c24092b..b0951a42259 100644 --- a/homeassistant/components/august/lock.py +++ b/homeassistant/components/august/lock.py @@ -91,7 +91,7 @@ class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity): return False @callback - def _update_from_data(self): + def _update_from_data(self) -> None: """Get the latest state of the sensor and update activity.""" activity_stream = self._data.activity_stream device_id = self._device_id diff --git a/homeassistant/components/august/sensor.py b/homeassistant/components/august/sensor.py index 94b883dba0d..babf8cda072 100644 --- a/homeassistant/components/august/sensor.py +++ b/homeassistant/components/august/sensor.py @@ -194,7 +194,7 @@ class AugustOperatorSensor(AugustEntityMixin, RestoreSensor): self._update_from_data() @callback - def _update_from_data(self): + def _update_from_data(self) -> None: """Get the latest state of the sensor and update activity.""" lock_activity = self._data.activity_stream.get_latest_device_activity( self._device_id, {ActivityType.LOCK_OPERATION}