1 """Support for Verisure cameras."""
3 from __future__
import annotations
8 from verisure
import Error
as VerisureError
17 async_get_current_platform,
21 from .const
import CONF_GIID, DOMAIN, LOGGER, SERVICE_CAPTURE_SMARTCAM
22 from .coordinator
import VerisureDataUpdateCoordinator
28 async_add_entities: AddEntitiesCallback,
30 """Set up Verisure sensors based on a config entry."""
31 coordinator: VerisureDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
34 platform.async_register_entity_service(
35 SERVICE_CAPTURE_SMARTCAM,
37 VerisureSmartcam.capture_smartcam.__name__,
42 for serial_number
in coordinator.data[
"cameras"]
47 """Representation of a Verisure camera."""
49 _attr_has_entity_name =
True
54 coordinator: VerisureDataUpdateCoordinator,
58 """Initialize Verisure File Camera component."""
66 self.
_image_image: str |
None =
None
67 self.
_image_id_image_id: str |
None =
None
71 """Return device information about this entity."""
72 area = self.coordinator.data[
"cameras"][self.
serial_numberserial_number][
"device"][
"area"]
75 manufacturer=
"Verisure",
78 via_device=(DOMAIN, self.coordinator.entry.data[CONF_GIID]),
79 configuration_url=
"https://mypages.verisure.com",
83 self, width: int |
None =
None, height: int |
None =
None
85 """Return image response."""
88 LOGGER.debug(
"No image to display")
90 LOGGER.debug(
"Trying to open %s", self.
_image_image)
95 """Check the contents of the image list."""
99 for image
in self.coordinator.imageseries:
107 new_image_id = new_image[
"mediaId"]
108 if new_image_id
in (
"-1", self.
_image_id_image_id):
109 LOGGER.debug(
"The image is the same, or loading image_id")
112 LOGGER.debug(
"Download new image %s", new_image_id)
113 new_image_path = os.path.join(self.
_directory_path_directory_path, f
"{new_image_id}.jpg")
114 new_image_url = new_image[
"contentUrl"]
115 self.coordinator.verisure.download_image(new_image_url, new_image_path)
116 LOGGER.debug(
"Old image_id=%s", self.
_image_id_image_id)
123 """Delete an old image."""
124 remove_image = os.path.join(self.
_directory_path_directory_path, f
"{self._image_id}.jpg")
126 os.remove(remove_image)
127 LOGGER.debug(
"Deleting old image %s", remove_image)
128 except OSError
as error:
129 if error.errno != errno.ENOENT:
133 """Capture a new picture from a smartcam."""
136 LOGGER.debug(
"Capturing new image from %s", self.
serial_numberserial_number)
137 except VerisureError
as ex:
138 LOGGER.error(
"Could not capture image, %s", ex)
141 """Entity added to Home Assistant."""
143 self.
hasshasshass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.
delete_imagedelete_image)
DeviceInfo device_info(self)
None capture_smartcam(self)
None __init__(self, VerisureDataUpdateCoordinator coordinator, str serial_number, str directory_path)
None delete_image(self, _=None)
None async_added_to_hass(self)
bytes|None camera_image(self, int|None width=None, int|None height=None)
None check_imagelist(self)
None update_smartcam_imageseries(self)
None smartcam_capture(self, str device_id)
None open(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)