Fix verisure deadlock (#48691)
parent
0544d94bd0
commit
0f757c3db2
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue