Migrate foscam to use entity platform entity services (#43775)
This commit is contained in:
parent
39e7b30ab6
commit
935ec59c56
1 changed files with 22 additions and 29 deletions
|
@ -13,14 +13,9 @@ from homeassistant.const import (
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.helpers.service import async_extract_entity_ids
|
|
||||||
|
|
||||||
from .const import (
|
from .const import DATA as FOSCAM_DATA, ENTITIES as FOSCAM_ENTITIES
|
||||||
DATA as FOSCAM_DATA,
|
|
||||||
DOMAIN as FOSCAM_DOMAIN,
|
|
||||||
ENTITIES as FOSCAM_ENTITIES,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -90,28 +85,26 @@ SERVICE_PTZ_SCHEMA = vol.Schema(
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Set up a Foscam IP Camera."""
|
"""Set up a Foscam IP Camera."""
|
||||||
|
platform = entity_platform.current_platform.get()
|
||||||
async def async_handle_ptz(service):
|
assert platform is not None
|
||||||
"""Handle PTZ service call."""
|
platform.async_register_entity_service(
|
||||||
movement = service.data[ATTR_MOVEMENT]
|
"ptz",
|
||||||
travel_time = service.data[ATTR_TRAVELTIME]
|
{
|
||||||
entity_ids = await async_extract_entity_ids(hass, service)
|
vol.Required(ATTR_MOVEMENT): vol.In(
|
||||||
|
[
|
||||||
if not entity_ids:
|
DIR_UP,
|
||||||
return
|
DIR_DOWN,
|
||||||
|
DIR_LEFT,
|
||||||
_LOGGER.debug("Moving '%s' camera(s): %s", movement, entity_ids)
|
DIR_RIGHT,
|
||||||
|
DIR_TOPLEFT,
|
||||||
all_cameras = hass.data[FOSCAM_DATA][FOSCAM_ENTITIES]
|
DIR_TOPRIGHT,
|
||||||
target_cameras = [
|
DIR_BOTTOMLEFT,
|
||||||
camera for camera in all_cameras if camera.entity_id in entity_ids
|
DIR_BOTTOMRIGHT,
|
||||||
]
|
]
|
||||||
|
),
|
||||||
for camera in target_cameras:
|
vol.Optional(ATTR_TRAVELTIME, default=DEFAULT_TRAVELTIME): cv.small_float,
|
||||||
await camera.async_perform_ptz(movement, travel_time)
|
},
|
||||||
|
"async_perform_ptz",
|
||||||
hass.services.async_register(
|
|
||||||
FOSCAM_DOMAIN, SERVICE_PTZ, async_handle_ptz, schema=SERVICE_PTZ_SCHEMA
|
|
||||||
)
|
)
|
||||||
|
|
||||||
camera = FoscamCamera(
|
camera = FoscamCamera(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue