mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Simplify synology_dsm service actions (#146612)
This commit is contained in:
parent
25e6eab008
commit
30dbd5a900
@ -45,7 +45,7 @@ CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Synology DSM component."""
|
||||
|
||||
await async_setup_services(hass)
|
||||
async_setup_services(hass)
|
||||
|
||||
return True
|
||||
|
||||
|
@ -7,7 +7,7 @@ from typing import cast
|
||||
|
||||
from synology_dsm.exceptions import SynologyDSMException
|
||||
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
|
||||
from .const import CONF_SERIAL, DOMAIN, SERVICE_REBOOT, SERVICE_SHUTDOWN, SERVICES
|
||||
from .coordinator import SynologyDSMConfigEntry
|
||||
@ -15,22 +15,17 @@ from .coordinator import SynologyDSMConfigEntry
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Service handler setup."""
|
||||
|
||||
async def service_handler(call: ServiceCall) -> None:
|
||||
async def _service_handler(call: ServiceCall) -> None:
|
||||
"""Handle service call."""
|
||||
serial: str | None = call.data.get(CONF_SERIAL)
|
||||
entries: list[SynologyDSMConfigEntry] = (
|
||||
hass.config_entries.async_loaded_entries(DOMAIN)
|
||||
call.hass.config_entries.async_loaded_entries(DOMAIN)
|
||||
)
|
||||
dsm_devices = {
|
||||
cast(str, entry.unique_id): entry.runtime_data for entry in entries
|
||||
}
|
||||
dsm_devices = {cast(str, entry.unique_id): entry.runtime_data for entry in entries}
|
||||
|
||||
if serial:
|
||||
entry: SynologyDSMConfigEntry | None = (
|
||||
hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, serial)
|
||||
call.hass.config_entries.async_entry_for_domain_unique_id(DOMAIN, serial)
|
||||
)
|
||||
assert entry
|
||||
dsm_device = entry.runtime_data
|
||||
@ -73,5 +68,10 @@ async def async_setup_services(hass: HomeAssistant) -> None:
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Service handler setup."""
|
||||
|
||||
for service in SERVICES:
|
||||
hass.services.async_register(DOMAIN, service, service_handler)
|
||||
hass.services.async_register(DOMAIN, service, _service_handler)
|
||||
|
Loading…
x
Reference in New Issue
Block a user