mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Avoid regenerating the mobile app schema every time a webhook is called (#96733)
Avoid regnerating the mobile app schema every time a webhook is called
This commit is contained in:
parent
d242eaa375
commit
51a7df162c
@ -144,6 +144,16 @@ WEBHOOK_PAYLOAD_SCHEMA = vol.Any(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SENSOR_SCHEMA_FULL = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Optional(ATTR_SENSOR_ATTRIBUTES, default={}): dict,
|
||||||
|
vol.Optional(ATTR_SENSOR_ICON, default="mdi:cellphone"): vol.Any(None, cv.icon),
|
||||||
|
vol.Required(ATTR_SENSOR_STATE): vol.Any(None, bool, int, float, str),
|
||||||
|
vol.Required(ATTR_SENSOR_TYPE): vol.In(SENSOR_TYPES),
|
||||||
|
vol.Required(ATTR_SENSOR_UNIQUE_ID): cv.string,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def validate_schema(schema):
|
def validate_schema(schema):
|
||||||
"""Decorate a webhook function with a schema."""
|
"""Decorate a webhook function with a schema."""
|
||||||
@ -636,18 +646,6 @@ async def webhook_update_sensor_states(
|
|||||||
hass: HomeAssistant, config_entry: ConfigEntry, data: list[dict[str, Any]]
|
hass: HomeAssistant, config_entry: ConfigEntry, data: list[dict[str, Any]]
|
||||||
) -> Response:
|
) -> Response:
|
||||||
"""Handle an update sensor states webhook."""
|
"""Handle an update sensor states webhook."""
|
||||||
sensor_schema_full = vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Optional(ATTR_SENSOR_ATTRIBUTES, default={}): dict,
|
|
||||||
vol.Optional(ATTR_SENSOR_ICON, default="mdi:cellphone"): vol.Any(
|
|
||||||
None, cv.icon
|
|
||||||
),
|
|
||||||
vol.Required(ATTR_SENSOR_STATE): vol.Any(None, bool, int, float, str),
|
|
||||||
vol.Required(ATTR_SENSOR_TYPE): vol.In(SENSOR_TYPES),
|
|
||||||
vol.Required(ATTR_SENSOR_UNIQUE_ID): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
device_name: str = config_entry.data[ATTR_DEVICE_NAME]
|
device_name: str = config_entry.data[ATTR_DEVICE_NAME]
|
||||||
resp: dict[str, Any] = {}
|
resp: dict[str, Any] = {}
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
@ -677,7 +675,7 @@ async def webhook_update_sensor_states(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sensor = sensor_schema_full(sensor)
|
sensor = SENSOR_SCHEMA_FULL(sensor)
|
||||||
except vol.Invalid as err:
|
except vol.Invalid as err:
|
||||||
err_msg = vol.humanize.humanize_error(sensor, err)
|
err_msg = vol.humanize.humanize_error(sensor, err)
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user