diff --git a/homeassistant/components/verisure/camera.py b/homeassistant/components/verisure/camera.py index c97d7f8c76c..cb159027c16 100644 --- a/homeassistant/components/verisure/camera.py +++ b/homeassistant/components/verisure/camera.py @@ -36,7 +36,7 @@ async def async_setup_entry( assert hass.config.config_dir async_add_entities( - VerisureSmartcam(hass, coordinator, serial_number, hass.config.config_dir) + VerisureSmartcam(coordinator, serial_number, hass.config.config_dir) for serial_number in coordinator.data["cameras"] ) @@ -48,7 +48,6 @@ class VerisureSmartcam(CoordinatorEntity, Camera): def __init__( self, - hass: HomeAssistant, coordinator: VerisureDataUpdateCoordinator, serial_number: str, directory_path: str, @@ -60,7 +59,6 @@ class VerisureSmartcam(CoordinatorEntity, Camera): self._directory_path = directory_path self._image = None self._image_id = None - hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, self.delete_image) @property def name(self) -> str: @@ -126,7 +124,7 @@ class VerisureSmartcam(CoordinatorEntity, Camera): self._image_id = new_image_id self._image = new_image_path - def delete_image(self) -> None: + def delete_image(self, _=None) -> None: """Delete an old image.""" remove_image = os.path.join( self._directory_path, "{}{}".format(self._image_id, ".jpg") @@ -145,3 +143,8 @@ class VerisureSmartcam(CoordinatorEntity, Camera): LOGGER.debug("Capturing new image from %s", self.serial_number) except VerisureError as ex: LOGGER.error("Could not capture image, %s", ex) + + async def async_added_to_hass(self) -> None: + """Entity added to Home Assistant.""" + await super().async_added_to_hass() + self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.delete_image)