mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Simplify reolink service actions (#146751)
This commit is contained in:
parent
d880ce6bb4
commit
a66e9a1a2c
@ -19,22 +19,20 @@ from .util import get_device_uid_and_ch, raise_translated_error
|
|||||||
ATTR_RINGTONE = "ringtone"
|
ATTR_RINGTONE = "ringtone"
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@raise_translated_error
|
||||||
def async_setup_services(hass: HomeAssistant) -> None:
|
async def _async_play_chime(service_call: ServiceCall) -> None:
|
||||||
"""Set up Reolink services."""
|
|
||||||
|
|
||||||
@raise_translated_error
|
|
||||||
async def async_play_chime(service_call: ServiceCall) -> None:
|
|
||||||
"""Play a ringtone."""
|
"""Play a ringtone."""
|
||||||
service_data = service_call.data
|
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]:
|
for device_id in service_data[ATTR_DEVICE_ID]:
|
||||||
config_entry = None
|
config_entry = None
|
||||||
device = device_registry.async_get(device_id)
|
device = device_registry.async_get(device_id)
|
||||||
if device is not None:
|
if device is not None:
|
||||||
for entry_id in device.config_entries:
|
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:
|
if config_entry is not None and config_entry.domain == DOMAIN:
|
||||||
break
|
break
|
||||||
if (
|
if (
|
||||||
@ -60,10 +58,15 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
|||||||
ringtone = service_data[ATTR_RINGTONE]
|
ringtone = service_data[ATTR_RINGTONE]
|
||||||
await chime.play(ChimeToneEnum[ringtone].value)
|
await chime.play(ChimeToneEnum[ringtone].value)
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_setup_services(hass: HomeAssistant) -> None:
|
||||||
|
"""Set up Reolink services."""
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
"play_chime",
|
"play_chime",
|
||||||
async_play_chime,
|
_async_play_chime,
|
||||||
schema=vol.Schema(
|
schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(ATTR_DEVICE_ID): list[str],
|
vol.Required(ATTR_DEVICE_ID): list[str],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user