mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add new mobile_app webhook command: get_zones (#22604)
## Description: Adds a new `mobile_app` webhook command, `get_zones`, which just returns all zones. ## Checklist: - [x] The code change is tested and works locally. - [x] Local tests pass with `tox`. **Your PR cannot be merged unless tests pass** - [x] There is no commented out code in this PR.
This commit is contained in:
@@ -9,6 +9,8 @@ from homeassistant.components.device_tracker import (ATTR_ATTRIBUTES,
|
||||
DOMAIN as DT_DOMAIN,
|
||||
SERVICE_SEE as DT_SEE)
|
||||
|
||||
from homeassistant.components.zone.const import DOMAIN as ZONE_DOMAIN
|
||||
|
||||
from homeassistant.const import (ATTR_DOMAIN, ATTR_SERVICE, ATTR_SERVICE_DATA,
|
||||
CONF_WEBHOOK_ID, HTTP_BAD_REQUEST,
|
||||
HTTP_CREATED)
|
||||
@@ -33,9 +35,10 @@ from .const import (ATTR_ALTITUDE, ATTR_BATTERY, ATTR_COURSE, ATTR_DEVICE_ID,
|
||||
DATA_STORE, DOMAIN, ERR_ENCRYPTION_REQUIRED,
|
||||
ERR_SENSOR_DUPLICATE_UNIQUE_ID, ERR_SENSOR_NOT_REGISTERED,
|
||||
SIGNAL_SENSOR_UPDATE, WEBHOOK_PAYLOAD_SCHEMA,
|
||||
WEBHOOK_SCHEMAS, WEBHOOK_TYPE_CALL_SERVICE,
|
||||
WEBHOOK_TYPE_FIRE_EVENT, WEBHOOK_TYPE_REGISTER_SENSOR,
|
||||
WEBHOOK_TYPE_RENDER_TEMPLATE, WEBHOOK_TYPE_UPDATE_LOCATION,
|
||||
WEBHOOK_SCHEMAS, WEBHOOK_TYPES, WEBHOOK_TYPE_CALL_SERVICE,
|
||||
WEBHOOK_TYPE_FIRE_EVENT, WEBHOOK_TYPE_GET_ZONES,
|
||||
WEBHOOK_TYPE_REGISTER_SENSOR, WEBHOOK_TYPE_RENDER_TEMPLATE,
|
||||
WEBHOOK_TYPE_UPDATE_LOCATION,
|
||||
WEBHOOK_TYPE_UPDATE_REGISTRATION,
|
||||
WEBHOOK_TYPE_UPDATE_SENSOR_STATES)
|
||||
|
||||
@@ -87,16 +90,19 @@ async def handle_webhook(hass: HomeAssistantType, webhook_id: str,
|
||||
enc_data = req_data[ATTR_WEBHOOK_ENCRYPTED_DATA]
|
||||
webhook_payload = _decrypt_payload(registration[CONF_SECRET], enc_data)
|
||||
|
||||
if webhook_type not in WEBHOOK_SCHEMAS:
|
||||
if webhook_type not in WEBHOOK_TYPES:
|
||||
_LOGGER.error('Received invalid webhook type: %s', webhook_type)
|
||||
return empty_okay_response()
|
||||
|
||||
try:
|
||||
data = WEBHOOK_SCHEMAS[webhook_type](webhook_payload)
|
||||
except vol.Invalid as ex:
|
||||
err = vol.humanize.humanize_error(webhook_payload, ex)
|
||||
_LOGGER.error('Received invalid webhook payload: %s', err)
|
||||
return empty_okay_response(headers=headers)
|
||||
data = webhook_payload
|
||||
|
||||
if webhook_type in WEBHOOK_SCHEMAS:
|
||||
try:
|
||||
data = WEBHOOK_SCHEMAS[webhook_type](webhook_payload)
|
||||
except vol.Invalid as ex:
|
||||
err = vol.humanize.humanize_error(webhook_payload, ex)
|
||||
_LOGGER.error('Received invalid webhook payload: %s', err)
|
||||
return empty_okay_response(headers=headers)
|
||||
|
||||
context = registration_context(registration)
|
||||
|
||||
@@ -261,3 +267,9 @@ async def handle_webhook(hass: HomeAssistantType, webhook_id: str,
|
||||
|
||||
return webhook_response(resp, registration=registration,
|
||||
headers=headers)
|
||||
|
||||
if webhook_type == WEBHOOK_TYPE_GET_ZONES:
|
||||
zones = (hass.states.get(entity_id) for entity_id
|
||||
in sorted(hass.states.async_entity_ids(ZONE_DOMAIN)))
|
||||
return webhook_response(list(zones), registration=registration,
|
||||
headers=headers)
|
||||
|
||||
Reference in New Issue
Block a user