Add Reolink chime play action (#123245)
* Add chime play service * fix supported_feature * finalize * add tests * Adjust to device service * fix issue * Add tests * actions -> services * fix styling * Use conftest fixture for test_chime * Update tests/components/reolink/test_services.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use ATTR_RINGTONE and rename chime_play to play_chime * Add translatable exceptions * fix styling * Remove option to use entity_id * fixes * Fix translations * fix * fix translation key * remove translation key * use callback for async_setup_services * fix styling * Add test_play_chime_service_unloaded --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
d8fe3c5377
commit
7334fb0125
8 changed files with 315 additions and 32 deletions
|
@ -2,11 +2,24 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from . import ReolinkData
|
||||
from .const import DOMAIN
|
||||
from .host import ReolinkHost
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReolinkData:
|
||||
"""Data for the Reolink integration."""
|
||||
|
||||
host: ReolinkHost
|
||||
device_coordinator: DataUpdateCoordinator[None]
|
||||
firmware_coordinator: DataUpdateCoordinator[None]
|
||||
|
||||
|
||||
def is_connected(hass: HomeAssistant, config_entry: config_entries.ConfigEntry) -> bool:
|
||||
|
@ -19,3 +32,25 @@ def is_connected(hass: HomeAssistant, config_entry: config_entries.ConfigEntry)
|
|||
and config_entry.state == config_entries.ConfigEntryState.LOADED
|
||||
and reolink_data.device_coordinator.last_update_success
|
||||
)
|
||||
|
||||
|
||||
def get_device_uid_and_ch(
|
||||
device: dr.DeviceEntry, host: ReolinkHost
|
||||
) -> tuple[list[str], int | None, bool]:
|
||||
"""Get the channel and the split device_uid from a reolink DeviceEntry."""
|
||||
device_uid = [
|
||||
dev_id[1].split("_") for dev_id in device.identifiers if dev_id[0] == DOMAIN
|
||||
][0]
|
||||
|
||||
is_chime = False
|
||||
if len(device_uid) < 2:
|
||||
# NVR itself
|
||||
ch = None
|
||||
elif device_uid[1].startswith("ch") and len(device_uid[1]) <= 5:
|
||||
ch = int(device_uid[1][2:])
|
||||
elif device_uid[1].startswith("chime"):
|
||||
ch = int(device_uid[1][5:])
|
||||
is_chime = True
|
||||
else:
|
||||
ch = host.api.channel_for_uid(device_uid[1])
|
||||
return (device_uid, ch, is_chime)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue