mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
Use async_get_device_and_config_entry service helper in simplisafe (#180147)
This commit is contained in:
@@ -18,12 +18,12 @@ from simplipy.system.v3 import (
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_DEVICE_ID
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||
from homeassistant.helpers.service import (
|
||||
async_get_device_and_config_entry,
|
||||
async_register_admin_service,
|
||||
verify_domain_control,
|
||||
)
|
||||
@@ -135,34 +135,18 @@ def _async_get_system_for_service_call(call: ServiceCall) -> SystemType:
|
||||
if TYPE_CHECKING:
|
||||
assert alarm_control_panel_device_entry.via_device_id
|
||||
|
||||
config_entry: SimpliSafeConfigEntry | None
|
||||
base_station_device_entry, config_entry = (
|
||||
dr.async_get_device_and_config_entry_for_domain(
|
||||
call.hass, alarm_control_panel_device_entry.via_device_id, domain=DOMAIN
|
||||
)
|
||||
config_entry: SimpliSafeConfigEntry
|
||||
base_station_device_entry, config_entry = async_get_device_and_config_entry(
|
||||
call.hass, DOMAIN, alarm_control_panel_device_entry.via_device_id
|
||||
)
|
||||
if base_station_device_entry is None:
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="no_base_station",
|
||||
translation_placeholders={"device_id": device_id},
|
||||
)
|
||||
|
||||
[system_id_str] = [
|
||||
identity[1]
|
||||
for identity in base_station_device_entry.identifiers
|
||||
if identity[0] == DOMAIN
|
||||
]
|
||||
system_id = int(system_id_str)
|
||||
|
||||
if config_entry is None or config_entry.state is not ConfigEntryState.LOADED:
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="no_system_for_device",
|
||||
translation_placeholders={"device_id": device_id},
|
||||
)
|
||||
|
||||
return config_entry.runtime_data.systems[system_id]
|
||||
return config_entry.runtime_data.systems[int(system_id_str)]
|
||||
|
||||
|
||||
@callback
|
||||
|
||||
@@ -34,12 +34,6 @@
|
||||
"invalid_device_id": {
|
||||
"message": "No device could be found for ID: {device_id}"
|
||||
},
|
||||
"no_base_station": {
|
||||
"message": "No base station could be found for device ID: {device_id}"
|
||||
},
|
||||
"no_system_for_device": {
|
||||
"message": "No SimpliSafe system could be found for device ID: {device_id}"
|
||||
},
|
||||
"set_system_properties_not_v3": {
|
||||
"message": "System properties can only be set on V3 systems."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user