Skip to content

Commit

Permalink
Add camera recording service to blink (#110612)
Browse files Browse the repository at this point in the history
Add camera clip recording service to blink

Revival of #46598 by @fronzbot, therefore:

Co-authored-by: Kevin Fronczak <kfronczak@gmail.com>
  • Loading branch information
mback2k and fronzbot committed May 13, 2024
1 parent 61b906e commit 4d5ae57
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion homeassistant/components/blink/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .const import (
DEFAULT_BRAND,
DOMAIN,
SERVICE_RECORD,
SERVICE_SAVE_RECENT_CLIPS,
SERVICE_SAVE_VIDEO,
SERVICE_TRIGGER,
Expand Down Expand Up @@ -50,6 +51,7 @@ async def async_setup_entry(
async_add_entities(entities)

platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(SERVICE_RECORD, {}, "record")
platform.async_register_entity_service(SERVICE_TRIGGER, {}, "trigger_camera")
platform.async_register_entity_service(
SERVICE_SAVE_RECENT_CLIPS,
Expand Down Expand Up @@ -94,7 +96,6 @@ async def async_enable_motion_detection(self) -> None:
"""Enable motion detection for the camera."""
try:
await self._camera.async_arm(True)

except TimeoutError as er:
raise HomeAssistantError(
translation_domain=DOMAIN,
Expand Down Expand Up @@ -127,6 +128,18 @@ def brand(self) -> str | None:
"""Return the camera brand."""
return DEFAULT_BRAND

async def record(self) -> None:
"""Trigger camera to record a clip."""
try:
await self._camera.record()
except TimeoutError as er:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="failed_clip",
) from er

self.async_write_ha_state()

async def trigger_camera(self) -> None:
"""Trigger camera to take a snapshot."""
try:
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/blink/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
TYPE_BATTERY = "battery"
TYPE_WIFI_STRENGTH = "wifi_strength"

SERVICE_RECORD = "record"
SERVICE_REFRESH = "blink_update"
SERVICE_TRIGGER = "trigger_camera"
SERVICE_SAVE_VIDEO = "save_video"
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/blink/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"services": {
"blink_update": "mdi:update",
"record": "mdi:video-box",
"trigger_camera": "mdi:image-refresh",
"save_video": "mdi:file-video",
"save_recent_clips": "mdi:file-video",
Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/blink/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ blink_update:
device:
integration: blink

record:
target:
entity:
integration: blink
domain: camera

trigger_camera:
target:
entity:
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/blink/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
}
}
},
"record": {
"name": "Record",
"description": "Requests camera to record a clip."
},
"trigger_camera": {
"name": "Trigger camera",
"description": "Requests camera to take new image."
Expand Down Expand Up @@ -123,6 +127,9 @@
"failed_disarm": {
"message": "Blink failed to disarm camera."
},
"failed_clip": {
"message": "Blink failed to record a clip."
},
"failed_snap": {
"message": "Blink failed to snap a picture."
},
Expand Down

0 comments on commit 4d5ae57

Please sign in to comment.