Move Blink trigger_camera service to camera platform (#35635)
parent
763ab79e6c
commit
94a9b364b0
|
@ -25,12 +25,10 @@ from .const import (
|
|||
SERVICE_REFRESH,
|
||||
SERVICE_SAVE_VIDEO,
|
||||
SERVICE_SEND_PIN,
|
||||
SERVICE_TRIGGER,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SERVICE_TRIGGER_SCHEMA = vol.Schema({vol.Required(CONF_NAME): cv.string})
|
||||
SERVICE_SAVE_VIDEO_SCHEMA = vol.Schema(
|
||||
{vol.Required(CONF_NAME): cv.string, vol.Required(CONF_FILENAME): cv.string}
|
||||
)
|
||||
|
@ -106,14 +104,6 @@ async def async_setup_entry(hass, entry):
|
|||
hass.config_entries.async_forward_entry_setup(entry, component)
|
||||
)
|
||||
|
||||
def trigger_camera(call):
|
||||
"""Trigger a camera."""
|
||||
cameras = hass.data[DOMAIN][entry.entry_id].cameras
|
||||
name = call.data[CONF_NAME]
|
||||
if name in cameras:
|
||||
cameras[name].snap_picture()
|
||||
blink_refresh()
|
||||
|
||||
def blink_refresh(event_time=None):
|
||||
"""Call blink to refresh info."""
|
||||
hass.data[DOMAIN][entry.entry_id].refresh(force_cache=True)
|
||||
|
@ -130,9 +120,6 @@ async def async_setup_entry(hass, entry):
|
|||
)
|
||||
|
||||
hass.services.async_register(DOMAIN, SERVICE_REFRESH, blink_refresh)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_TRIGGER, trigger_camera, schema=SERVICE_TRIGGER_SCHEMA
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_SAVE_VIDEO, async_save_video, schema=SERVICE_SAVE_VIDEO_SCHEMA
|
||||
)
|
||||
|
@ -163,7 +150,6 @@ async def async_unload_entry(hass, entry):
|
|||
return True
|
||||
|
||||
hass.services.async_remove(DOMAIN, SERVICE_REFRESH)
|
||||
hass.services.async_remove(DOMAIN, SERVICE_TRIGGER)
|
||||
hass.services.async_remove(DOMAIN, SERVICE_SAVE_VIDEO_SCHEMA)
|
||||
hass.services.async_remove(DOMAIN, SERVICE_SEND_PIN)
|
||||
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
"""Support for Blink system camera."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.camera import Camera
|
||||
import voluptuous as vol
|
||||
|
||||
from .const import DEFAULT_BRAND, DOMAIN
|
||||
from homeassistant.components.camera import Camera
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.helpers import entity_platform
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from .const import DEFAULT_BRAND, DOMAIN, SERVICE_TRIGGER
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_VIDEO_CLIP = "video"
|
||||
ATTR_IMAGE = "image"
|
||||
|
||||
SERVICE_TRIGGER_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids})
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config, async_add_entities):
|
||||
"""Set up a Blink Camera."""
|
||||
|
@ -20,6 +27,12 @@ async def async_setup_entry(hass, config, async_add_entities):
|
|||
|
||||
async_add_entities(entities)
|
||||
|
||||
platform = entity_platform.current_platform.get()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_TRIGGER, SERVICE_TRIGGER_SCHEMA, "trigger_camera"
|
||||
)
|
||||
|
||||
|
||||
class BlinkCamera(Camera):
|
||||
"""An implementation of a Blink Camera."""
|
||||
|
@ -69,6 +82,11 @@ class BlinkCamera(Camera):
|
|||
"""Return the camera brand."""
|
||||
return DEFAULT_BRAND
|
||||
|
||||
def trigger_camera(self):
|
||||
"""Trigger camera to take a snapshot."""
|
||||
self._camera.snap_picture()
|
||||
self.data.refresh()
|
||||
|
||||
def camera_image(self):
|
||||
"""Return a still image response from the camera."""
|
||||
return self._camera.image_from_cache.content
|
||||
|
|
|
@ -4,11 +4,11 @@ blink_update:
|
|||
description: Force a refresh.
|
||||
|
||||
trigger_camera:
|
||||
description: Request named camera to take new image.
|
||||
description: Request camera to take new image.
|
||||
fields:
|
||||
name:
|
||||
description: Name of camera to take new image.
|
||||
example: "Living Room"
|
||||
entity_id:
|
||||
description: Name(s) of camera entities to take new image.
|
||||
example: "camera.living_room_camera"
|
||||
|
||||
save_video:
|
||||
description: Save last recorded video clip to local file.
|
||||
|
|
Loading…
Reference in New Issue