1 """Support for Blink system camera."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
9 from requests.exceptions
import ChunkedEncodingError
10 import voluptuous
as vol
26 SERVICE_SAVE_RECENT_CLIPS,
30 from .coordinator
import BlinkConfigEntry, BlinkUpdateCoordinator
32 _LOGGER = logging.getLogger(__name__)
34 ATTR_VIDEO_CLIP =
"video"
41 config_entry: BlinkConfigEntry,
42 async_add_entities: AddEntitiesCallback,
44 """Set up a Blink Camera."""
46 coordinator = config_entry.runtime_data
49 for name, camera
in coordinator.api.cameras.items()
54 platform = entity_platform.async_get_current_platform()
55 platform.async_register_entity_service(SERVICE_RECORD,
None,
"record")
56 platform.async_register_entity_service(SERVICE_TRIGGER,
None,
"trigger_camera")
57 platform.async_register_entity_service(
58 SERVICE_SAVE_RECENT_CLIPS,
59 {vol.Required(CONF_FILE_PATH): cv.string},
62 platform.async_register_entity_service(
64 {vol.Required(CONF_FILENAME): cv.string},
70 """An implementation of a Blink Camera."""
72 _attr_has_entity_name =
True
75 def __init__(self, coordinator: BlinkUpdateCoordinator, name, camera) ->
None:
76 """Initialize a camera."""
82 identifiers={(DOMAIN, camera.serial)},
83 serial_number=camera.serial,
84 sw_version=camera.version,
86 manufacturer=DEFAULT_BRAND,
87 model=camera.camera_type,
89 _LOGGER.debug(
"Initialized blink camera %s", self.
_camera_camera.name)
93 """Return the camera attributes."""
94 return self.
_camera_camera.attributes
97 """Enable motion detection for the camera."""
99 await self.
_camera_camera.async_arm(
True)
100 except TimeoutError
as er:
102 translation_domain=DOMAIN,
103 translation_key=
"failed_arm",
106 self.
_camera_camera.motion_enabled =
True
110 """Disable motion detection for the camera."""
112 await self.
_camera_camera.async_arm(
False)
113 except TimeoutError
as er:
115 translation_domain=DOMAIN,
116 translation_key=
"failed_disarm",
119 self.
_camera_camera.motion_enabled =
False
124 """Return the state of the camera."""
129 """Return the camera brand."""
133 """Trigger camera to record a clip."""
136 except TimeoutError
as er:
138 translation_domain=DOMAIN,
139 translation_key=
"failed_clip",
145 """Trigger camera to take a snapshot."""
147 await self.
_camera_camera.snap_picture()
148 except TimeoutError
as er:
150 translation_domain=DOMAIN,
151 translation_key=
"failed_snap",
157 self, width: int |
None =
None, height: int |
None =
None
159 """Return a still image response from the camera."""
161 return self.
_camera_camera.image_from_cache
162 except ChunkedEncodingError:
163 _LOGGER.debug(
"Could not retrieve image for %s", self.
_camera_camera.name)
166 _LOGGER.debug(
"No cached image for %s", self.
_camera_camera.name)
170 """Save multiple recent clips to output directory."""
171 if not self.
hasshasshass.config.is_allowed_path(file_path):
173 translation_domain=DOMAIN,
174 translation_key=
"no_path",
175 translation_placeholders={
"target": file_path},
180 except OSError
as err:
183 translation_domain=DOMAIN,
184 translation_key=
"cant_write",
188 """Handle save video service calls."""
189 if not self.
hasshasshass.config.is_allowed_path(filename):
191 translation_domain=DOMAIN,
192 translation_key=
"no_path",
193 translation_placeholders={
"target": filename},
197 await self.
_camera_camera.video_to_file(filename)
198 except OSError
as err:
201 translation_domain=DOMAIN,
202 translation_key=
"cant_write",
None async_enable_motion_detection(self)
None save_recent_clips(self, file_path)
None save_video(self, filename)
None trigger_camera(self)
Mapping[str, Any]|None extra_state_attributes(self)
bool motion_detection_enabled(self)
None async_disable_motion_detection(self)
bytes|None camera_image(self, int|None width=None, int|None height=None)
None __init__(self, BlinkUpdateCoordinator coordinator, name, camera)
None async_write_ha_state(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, BlinkConfigEntry config_entry, AddEntitiesCallback async_add_entities)