Simplify reolink service actions (#146751)

pull/145004/head^2
epenet 2025-06-13 18:08:59 +02:00 committed by GitHub
parent d880ce6bb4
commit a66e9a1a2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 41 additions and 38 deletions

View File

@ -19,22 +19,20 @@ from .util import get_device_uid_and_ch, raise_translated_error
ATTR_RINGTONE = "ringtone"
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up Reolink services."""
@raise_translated_error
async def async_play_chime(service_call: ServiceCall) -> None:
@raise_translated_error
async def _async_play_chime(service_call: ServiceCall) -> None:
"""Play a ringtone."""
service_data = service_call.data
device_registry = dr.async_get(hass)
device_registry = dr.async_get(service_call.hass)
for device_id in service_data[ATTR_DEVICE_ID]:
config_entry = None
device = device_registry.async_get(device_id)
if device is not None:
for entry_id in device.config_entries:
config_entry = hass.config_entries.async_get_entry(entry_id)
config_entry = service_call.hass.config_entries.async_get_entry(
entry_id
)
if config_entry is not None and config_entry.domain == DOMAIN:
break
if (
@ -60,10 +58,15 @@ def async_setup_services(hass: HomeAssistant) -> None:
ringtone = service_data[ATTR_RINGTONE]
await chime.play(ChimeToneEnum[ringtone].value)
@callback
def async_setup_services(hass: HomeAssistant) -> None:
"""Set up Reolink services."""
hass.services.async_register(
DOMAIN,
"play_chime",
async_play_chime,
_async_play_chime,
schema=vol.Schema(
{
vol.Required(ATTR_DEVICE_ID): list[str],