mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Tidy up service call for bosch_alarm (#145306)
tidy up service call for bosch_alarm
This commit is contained in:
parent
e39c8e350c
commit
d15a1a6711
@ -38,36 +38,37 @@ SET_DATE_TIME_SCHEMA = vol.Schema(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_set_panel_date(call: ServiceCall) -> None:
|
||||||
|
"""Set the date and time on a bosch alarm panel."""
|
||||||
|
config_entry: BoschAlarmConfigEntry | None
|
||||||
|
value: dt.datetime = call.data.get(ATTR_DATETIME, dt_util.now())
|
||||||
|
entry_id = call.data[ATTR_CONFIG_ENTRY_ID]
|
||||||
|
if not (config_entry := call.hass.config_entries.async_get_entry(entry_id)):
|
||||||
|
raise ServiceValidationError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="integration_not_found",
|
||||||
|
translation_placeholders={"target": entry_id},
|
||||||
|
)
|
||||||
|
if config_entry.state is not ConfigEntryState.LOADED:
|
||||||
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="not_loaded",
|
||||||
|
translation_placeholders={"target": config_entry.title},
|
||||||
|
)
|
||||||
|
panel = config_entry.runtime_data
|
||||||
|
try:
|
||||||
|
await panel.set_panel_date(value)
|
||||||
|
except asyncio.InvalidStateError as err:
|
||||||
|
raise HomeAssistantError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="connection_error",
|
||||||
|
translation_placeholders={"target": config_entry.title},
|
||||||
|
) from err
|
||||||
|
|
||||||
|
|
||||||
def setup_services(hass: HomeAssistant) -> None:
|
def setup_services(hass: HomeAssistant) -> None:
|
||||||
"""Set up the services for the bosch alarm integration."""
|
"""Set up the services for the bosch alarm integration."""
|
||||||
|
|
||||||
async def async_set_panel_date(call: ServiceCall) -> None:
|
|
||||||
"""Set the date and time on a bosch alarm panel."""
|
|
||||||
config_entry: BoschAlarmConfigEntry | None
|
|
||||||
value: dt.datetime = call.data.get(ATTR_DATETIME, dt_util.now())
|
|
||||||
entry_id = call.data[ATTR_CONFIG_ENTRY_ID]
|
|
||||||
if not (config_entry := hass.config_entries.async_get_entry(entry_id)):
|
|
||||||
raise ServiceValidationError(
|
|
||||||
translation_domain=DOMAIN,
|
|
||||||
translation_key="integration_not_found",
|
|
||||||
translation_placeholders={"target": entry_id},
|
|
||||||
)
|
|
||||||
if config_entry.state is not ConfigEntryState.LOADED:
|
|
||||||
raise HomeAssistantError(
|
|
||||||
translation_domain=DOMAIN,
|
|
||||||
translation_key="not_loaded",
|
|
||||||
translation_placeholders={"target": config_entry.title},
|
|
||||||
)
|
|
||||||
panel = config_entry.runtime_data
|
|
||||||
try:
|
|
||||||
await panel.set_panel_date(value)
|
|
||||||
except asyncio.InvalidStateError as err:
|
|
||||||
raise HomeAssistantError(
|
|
||||||
translation_domain=DOMAIN,
|
|
||||||
translation_key="connection_error",
|
|
||||||
translation_placeholders={"target": config_entry.title},
|
|
||||||
) from err
|
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_SET_DATE_TIME,
|
SERVICE_SET_DATE_TIME,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user