mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Store Shelly RPC entity descriptions as tuples (#193663)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
6571e30cb9
commit
887a7afbe7
@@ -230,47 +230,52 @@ REST_SENSORS: Final = {
|
||||
),
|
||||
}
|
||||
|
||||
RPC_SENSORS: Final = {
|
||||
"input": RpcBinarySensorDescription(
|
||||
RPC_SENSORS: Final = (
|
||||
RpcBinarySensorDescription(
|
||||
key="input",
|
||||
components=("input",),
|
||||
sub_key="state",
|
||||
translation_key="input",
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
removal_condition=is_rpc_momentary_input,
|
||||
),
|
||||
"cloud": RpcBinarySensorDescription(
|
||||
RpcBinarySensorDescription(
|
||||
key="cloud",
|
||||
components=("cloud",),
|
||||
sub_key="connected",
|
||||
translation_key="cloud",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
"external_power": RpcBinarySensorDescription(
|
||||
key="devicepower",
|
||||
RpcBinarySensorDescription(
|
||||
key="external_power",
|
||||
components=("devicepower",),
|
||||
sub_key="external",
|
||||
translation_key="external_power",
|
||||
value=lambda status, _: status["present"],
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
"cb_output": RpcBinarySensorDescription(
|
||||
key="cb",
|
||||
RpcBinarySensorDescription(
|
||||
key="cb_output",
|
||||
components=("cb",),
|
||||
sub_key="output",
|
||||
translation_key="output",
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
"cb_safety": RpcBinarySensorDescription(
|
||||
key="cb",
|
||||
RpcBinarySensorDescription(
|
||||
key="cb_safety",
|
||||
components=("cb",),
|
||||
sub_key="safety",
|
||||
translation_key="safety_switch",
|
||||
device_class=BinarySensorDeviceClass.LOCK,
|
||||
value=lambda status, _: not status,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
"overtemp": RpcBinarySensorDescription(
|
||||
key="switch",
|
||||
RpcBinarySensorDescription(
|
||||
key="overtemp",
|
||||
components=("switch", "cover"),
|
||||
sub_key="errors",
|
||||
translation_key="overheating",
|
||||
@@ -279,8 +284,8 @@ RPC_SENSORS: Final = {
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
supported=lambda status: status.get("apower") is not None,
|
||||
),
|
||||
"overpower": RpcBinarySensorDescription(
|
||||
key="switch",
|
||||
RpcBinarySensorDescription(
|
||||
key="overpower",
|
||||
components=("switch", "cover"),
|
||||
sub_key="errors",
|
||||
translation_key="overpowering",
|
||||
@@ -289,8 +294,8 @@ RPC_SENSORS: Final = {
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
supported=lambda status: status.get("apower") is not None,
|
||||
),
|
||||
"overvoltage": RpcBinarySensorDescription(
|
||||
key="switch",
|
||||
RpcBinarySensorDescription(
|
||||
key="overvoltage",
|
||||
components=("switch", "cover"),
|
||||
sub_key="errors",
|
||||
translation_key="overvoltage",
|
||||
@@ -299,8 +304,8 @@ RPC_SENSORS: Final = {
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
supported=lambda status: status.get("apower") is not None,
|
||||
),
|
||||
"overcurrent": RpcBinarySensorDescription(
|
||||
key="switch",
|
||||
RpcBinarySensorDescription(
|
||||
key="overcurrent",
|
||||
components=("switch", "cover"),
|
||||
sub_key="errors",
|
||||
translation_key="overcurrent",
|
||||
@@ -309,37 +314,42 @@ RPC_SENSORS: Final = {
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
supported=lambda status: status.get("apower") is not None,
|
||||
),
|
||||
"smoke": RpcBinarySensorDescription(
|
||||
RpcBinarySensorDescription(
|
||||
key="smoke",
|
||||
components=("smoke",),
|
||||
sub_key="alarm",
|
||||
device_class=BinarySensorDeviceClass.SMOKE,
|
||||
),
|
||||
"restart": RpcBinarySensorDescription(
|
||||
key="sys",
|
||||
RpcBinarySensorDescription(
|
||||
key="restart",
|
||||
components=("sys",),
|
||||
sub_key="restart_required",
|
||||
translation_key="restart_required",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
"boolean_generic": RpcBinarySensorDescription(
|
||||
key="boolean",
|
||||
RpcBinarySensorDescription(
|
||||
key="boolean_generic",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
removal_condition=lambda config, _, key: (
|
||||
not is_view_for_platform(config, key, BINARY_SENSOR_DOMAIN)
|
||||
),
|
||||
role=ROLE_GENERIC,
|
||||
),
|
||||
"boolean_has_power": RpcBinarySensorDescription(
|
||||
key="boolean",
|
||||
RpcBinarySensorDescription(
|
||||
key="boolean_has_power",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
role="has_power",
|
||||
models={MODEL_FRANKEVER_WATER_VALVE},
|
||||
),
|
||||
"calibration": RpcBinarySensorDescription(
|
||||
key="blutrv",
|
||||
RpcBinarySensorDescription(
|
||||
key="calibration",
|
||||
components=("blutrv",),
|
||||
sub_key="errors",
|
||||
translation_key="calibration",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
@@ -347,20 +357,23 @@ RPC_SENSORS: Final = {
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_class=RpcBluTrvBinarySensor,
|
||||
),
|
||||
"flood": RpcBinarySensorDescription(
|
||||
RpcBinarySensorDescription(
|
||||
key="flood",
|
||||
components=("flood",),
|
||||
sub_key="alarm",
|
||||
translation_key="flood",
|
||||
device_class=BinarySensorDeviceClass.MOISTURE,
|
||||
),
|
||||
"mute": RpcBinarySensorDescription(
|
||||
key="flood",
|
||||
RpcBinarySensorDescription(
|
||||
key="mute",
|
||||
components=("flood",),
|
||||
sub_key="mute",
|
||||
translation_key="mute",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
"flood_cable_unplugged": RpcBinarySensorDescription(
|
||||
key="flood",
|
||||
RpcBinarySensorDescription(
|
||||
key="flood_cable_unplugged",
|
||||
components=("flood",),
|
||||
sub_key="errors",
|
||||
value=lambda status, _: (
|
||||
False if status is None else "cable_unplugged" in status
|
||||
@@ -371,26 +384,30 @@ RPC_SENSORS: Final = {
|
||||
supported=lambda status: status.get("alarm") is not None,
|
||||
models={MODEL_FLOOD_G4},
|
||||
),
|
||||
"presence_num_objects": RpcBinarySensorDescription(
|
||||
key="presence",
|
||||
RpcBinarySensorDescription(
|
||||
key="presence_num_objects",
|
||||
components=("presence",),
|
||||
sub_key="num_objects",
|
||||
value=lambda status, _: bool(status),
|
||||
device_class=BinarySensorDeviceClass.OCCUPANCY,
|
||||
entity_class=RpcPresenceBinarySensor,
|
||||
),
|
||||
"presencezone_state": RpcBinarySensorDescription(
|
||||
key="presencezone",
|
||||
RpcBinarySensorDescription(
|
||||
key="presencezone_state",
|
||||
components=("presencezone",),
|
||||
sub_key="value",
|
||||
device_class=BinarySensorDeviceClass.OCCUPANCY,
|
||||
entity_class=RpcPresenceBinarySensor,
|
||||
),
|
||||
"occupancy": RpcBinarySensorDescription(
|
||||
RpcBinarySensorDescription(
|
||||
key="occupancy",
|
||||
components=("occupancy",),
|
||||
sub_key="value",
|
||||
device_class=BinarySensorDeviceClass.OCCUPANCY,
|
||||
),
|
||||
"cury_tilt": RpcBinarySensorDescription(
|
||||
key="cury",
|
||||
RpcBinarySensorDescription(
|
||||
key="cury_tilt",
|
||||
components=("cury",),
|
||||
sub_key="errors",
|
||||
translation_key="tilt",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
@@ -400,8 +417,9 @@ RPC_SENSORS: Final = {
|
||||
),
|
||||
supported=lambda status: status.get("slots") is not None,
|
||||
),
|
||||
"cury_rotation": RpcBinarySensorDescription(
|
||||
key="cury",
|
||||
RpcBinarySensorDescription(
|
||||
key="cury_rotation",
|
||||
components=("cury",),
|
||||
sub_key="errors",
|
||||
translation_key="rotation",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
@@ -411,24 +429,27 @@ RPC_SENSORS: Final = {
|
||||
),
|
||||
supported=lambda status: status.get("slots") is not None,
|
||||
),
|
||||
"camera_motion": RpcBinarySensorDescription(
|
||||
key="camera",
|
||||
RpcBinarySensorDescription(
|
||||
key="camera_motion",
|
||||
components=("camera",),
|
||||
sub_key="motion",
|
||||
device_class=BinarySensorDeviceClass.MOTION,
|
||||
),
|
||||
"camerazone_motion": RpcBinarySensorDescription(
|
||||
key="camerazone",
|
||||
RpcBinarySensorDescription(
|
||||
key="camerazone_motion",
|
||||
components=("camerazone",),
|
||||
sub_key="motion",
|
||||
device_class=BinarySensorDeviceClass.MOTION,
|
||||
entity_class=RpcCameraZoneBinarySensor,
|
||||
),
|
||||
"motion": RpcBinarySensorDescription(
|
||||
RpcBinarySensorDescription(
|
||||
key="motion",
|
||||
components=("motion",),
|
||||
sub_key="motion",
|
||||
device_class=BinarySensorDeviceClass.MOTION,
|
||||
removal_condition=lambda config, _, key: not config[key].get("enable", True),
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -376,38 +376,44 @@ class RpcSleepingSmokeMuteButton(ShellySleepingRpcAttributeEntity, ButtonEntity)
|
||||
return False
|
||||
|
||||
|
||||
RPC_BUTTONS = {
|
||||
"button_generic": RpcButtonDescription(
|
||||
key="button",
|
||||
RPC_BUTTONS = (
|
||||
RpcButtonDescription(
|
||||
key="button_generic",
|
||||
components=("button",),
|
||||
role=ROLE_GENERIC,
|
||||
),
|
||||
"button_open": RpcButtonDescription(
|
||||
key="button",
|
||||
RpcButtonDescription(
|
||||
key="button_open",
|
||||
components=("button",),
|
||||
translation_key="open",
|
||||
entity_registry_enabled_default=False,
|
||||
role="open",
|
||||
models={MODEL_FRANKEVER_WATER_VALVE},
|
||||
),
|
||||
"button_close": RpcButtonDescription(
|
||||
key="button",
|
||||
RpcButtonDescription(
|
||||
key="button_close",
|
||||
components=("button",),
|
||||
translation_key="close",
|
||||
entity_registry_enabled_default=False,
|
||||
role="close",
|
||||
models={MODEL_FRANKEVER_WATER_VALVE},
|
||||
),
|
||||
"calibrate": RpcButtonDescription(
|
||||
key="blutrv",
|
||||
RpcButtonDescription(
|
||||
key="calibrate",
|
||||
components=("blutrv",),
|
||||
translation_key="calibrate",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
entity_class=ShellyBluTrvButton,
|
||||
),
|
||||
"smoke_mute": RpcButtonDescription(
|
||||
key="smoke",
|
||||
RpcButtonDescription(
|
||||
key="smoke_mute",
|
||||
components=("smoke",),
|
||||
sub_key="mute",
|
||||
translation_key="mute_alarm",
|
||||
),
|
||||
"ircode": RpcButtonDescription(
|
||||
RpcButtonDescription(
|
||||
key="ircode",
|
||||
components=("ircode",),
|
||||
entity_class=RpcIrCodeButton,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -35,23 +35,25 @@ class RpcCameraEntityDescription(RpcEntityDescription, CameraEntityDescription):
|
||||
stream: int
|
||||
|
||||
|
||||
RPC_CAMERA_ENTITIES: Final = {
|
||||
"stream_0": RpcCameraEntityDescription(
|
||||
key="camera",
|
||||
RPC_CAMERA_ENTITIES: Final = (
|
||||
RpcCameraEntityDescription(
|
||||
key="stream_0",
|
||||
components=("camera",),
|
||||
stream=0,
|
||||
translation_key="stream",
|
||||
translation_placeholders={"stream_id": "0"},
|
||||
removal_condition=lambda config, _, key: not config[key]["rtsp"]["enable"],
|
||||
),
|
||||
"stream_1": RpcCameraEntityDescription(
|
||||
key="camera",
|
||||
RpcCameraEntityDescription(
|
||||
key="stream_1",
|
||||
components=("camera",),
|
||||
stream=1,
|
||||
translation_key="stream",
|
||||
translation_placeholders={"stream_id": "1"},
|
||||
entity_registry_enabled_default=False,
|
||||
removal_condition=lambda config, _, key: not config[key]["rtsp"]["enable"],
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -270,14 +270,15 @@ class RpcLinkedgoThermostatClimate(ShellyRpcAttributeEntity, ClimateEntity):
|
||||
)
|
||||
|
||||
|
||||
RPC_LINKEDGO_THERMOSTAT: dict[str, RpcClimateDescription] = {
|
||||
"linkedgo_thermostat_climate": RpcClimateDescription(
|
||||
key="number",
|
||||
RPC_LINKEDGO_THERMOSTAT: tuple[RpcClimateDescription, ...] = (
|
||||
RpcClimateDescription(
|
||||
key="linkedgo_thermostat_climate",
|
||||
components=("number",),
|
||||
sub_key="value",
|
||||
role="target_temperature",
|
||||
models={MODEL_LINKEDGO_ST802_THERMOSTAT, MODEL_LINKEDGO_ST1820_THERMOSTAT},
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -50,11 +50,12 @@ BLOCK_COVERS = {
|
||||
)
|
||||
}
|
||||
|
||||
RPC_COVERS = {
|
||||
"cover": RpcCoverDescription(
|
||||
RPC_COVERS = (
|
||||
RpcCoverDescription(
|
||||
key="cover",
|
||||
components=("cover",),
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Shelly entity helper."""
|
||||
|
||||
from collections.abc import Awaitable, Callable, Coroutine, Mapping
|
||||
from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from functools import partial, wraps
|
||||
from typing import Any, Concatenate, cast, override
|
||||
@@ -146,7 +146,7 @@ def async_setup_entry_rpc(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ShellyConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
sensors: Mapping[str, RpcEntityDescription],
|
||||
sensors: Iterable[RpcEntityDescription],
|
||||
sensor_class: Callable,
|
||||
) -> None:
|
||||
"""Set up RPC entities."""
|
||||
@@ -181,7 +181,7 @@ def async_setup_rpc_attribute_entities(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ShellyConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
sensors: Mapping[str, RpcEntityDescription],
|
||||
sensors: Iterable[RpcEntityDescription],
|
||||
sensor_class: Callable,
|
||||
*,
|
||||
skip_registered: bool = False,
|
||||
@@ -196,11 +196,11 @@ def async_setup_rpc_attribute_entities(
|
||||
assert polling_coordinator
|
||||
|
||||
entities = []
|
||||
for sensor_id, description in sensors.items():
|
||||
for description in sensors:
|
||||
legacy_ids = description.legacy_ids or {}
|
||||
key_instances = [
|
||||
(key, legacy_ids.get(component, sensor_id))
|
||||
for component in description.components or (description.key,)
|
||||
(key, legacy_ids.get(component, description.key))
|
||||
for component in description.components
|
||||
for key in get_rpc_key_instances(coordinator.device.status, component)
|
||||
]
|
||||
|
||||
@@ -268,7 +268,7 @@ def async_restore_rpc_attribute_entities(
|
||||
config_entry: ShellyConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
coordinator: ShellyRpcCoordinator,
|
||||
sensors: Mapping[str, RpcEntityDescription],
|
||||
sensors: Iterable[RpcEntityDescription],
|
||||
sensor_class: Callable,
|
||||
) -> None:
|
||||
"""Restore RPC attributes entities."""
|
||||
@@ -278,11 +278,7 @@ def async_restore_rpc_attribute_entities(
|
||||
entries = er.async_entries_for_config_entry(ent_reg, config_entry.entry_id)
|
||||
|
||||
domain = sensor_class.__module__.split(".")[-1]
|
||||
descriptions = {
|
||||
legacy_id: description
|
||||
for description in sensors.values()
|
||||
for legacy_id in (description.legacy_ids or {}).values()
|
||||
} | dict(sensors)
|
||||
descriptions = get_rpc_descriptions_by_attribute(sensors)
|
||||
|
||||
for entry in entries:
|
||||
if entry.domain != domain:
|
||||
@@ -338,10 +334,9 @@ class BlockEntityDescription(EntityDescription):
|
||||
class RpcEntityDescription(EntityDescription):
|
||||
"""Class to describe a RPC entity."""
|
||||
|
||||
components: tuple[str, ...]
|
||||
sub_key: str | None = None
|
||||
# Components the description applies to, defaults to the key
|
||||
components: tuple[str, ...] | None = None
|
||||
# Description ID per component, keeps unique IDs from before a merge
|
||||
# Unique ID attribute per component, keeps unique IDs from before a merge
|
||||
legacy_ids: Mapping[str, str] | None = None
|
||||
|
||||
value: Callable[[Any, Any], Any] | None = None
|
||||
@@ -355,6 +350,19 @@ class RpcEntityDescription(EntityDescription):
|
||||
models: set[str] | None = None
|
||||
|
||||
|
||||
def get_rpc_descriptions_by_attribute(
|
||||
descriptions: Iterable[RpcEntityDescription],
|
||||
) -> dict[str, RpcEntityDescription]:
|
||||
"""Return the RPC descriptions by the attribute of their unique IDs."""
|
||||
by_attribute: dict[str, RpcEntityDescription] = {}
|
||||
for description in descriptions:
|
||||
for attribute in (description.key, *(description.legacy_ids or {}).values()):
|
||||
if attribute in by_attribute:
|
||||
raise ValueError(f"Duplicate RPC description attribute: {attribute}")
|
||||
by_attribute[attribute] = description
|
||||
return by_attribute
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RestEntityDescription(EntityDescription):
|
||||
"""Class to describe a REST entity."""
|
||||
|
||||
@@ -33,9 +33,9 @@ class RpcFanDescription(RpcEntityDescription, FanEntityDescription):
|
||||
"""Description for a Shelly RPC fan entity."""
|
||||
|
||||
|
||||
RPC_FANS: Final = {
|
||||
"fan": RpcFanDescription(key="fan", translation_key="fan"),
|
||||
}
|
||||
RPC_FANS: Final = (
|
||||
RpcFanDescription(key="fan", components=("fan",), translation_key="fan"),
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -80,19 +80,21 @@ class ShellyInfraredReceiver(ShellyRpcAttributeEntity, InfraredReceiverEntity):
|
||||
self._handle_received_signal(InfraredReceivedSignal(timings=timings))
|
||||
|
||||
|
||||
RPC_INFRARED_ENTITIES: Final = {
|
||||
"infrared_emitter": RpcInfraredEmitterEntityDescription(
|
||||
key="ir",
|
||||
RPC_INFRARED_ENTITIES: Final = (
|
||||
RpcInfraredEmitterEntityDescription(
|
||||
key="infrared_emitter",
|
||||
components=("ir",),
|
||||
translation_key="infrared_emitter",
|
||||
entity_class=ShellyInfraredEmitter,
|
||||
),
|
||||
"infrared_receiver": RpcInfraredReceiverEntityDescription(
|
||||
key="ir",
|
||||
RpcInfraredReceiverEntityDescription(
|
||||
key="infrared_receiver",
|
||||
components=("ir",),
|
||||
translation_key="infrared_receiver",
|
||||
entity_class=ShellyInfraredReceiver,
|
||||
removal_condition=lambda config, _, key: not config[key].get("raw_receive"),
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -594,47 +594,54 @@ class RpcShellyRgbwLight(RpcShellyLightBase):
|
||||
_attr_supported_features = LightEntityFeature.TRANSITION
|
||||
|
||||
|
||||
LIGHTS: Final = {
|
||||
"switch": RpcEntityDescription(
|
||||
LIGHTS: Final = (
|
||||
RpcEntityDescription(
|
||||
key="switch",
|
||||
components=("switch",),
|
||||
sub_key="output",
|
||||
removal_condition=lambda config, _status, key: (
|
||||
not is_rpc_channel_type_light(config, get_rpc_key_id(key))
|
||||
),
|
||||
entity_class=RpcShellySwitchAsLight,
|
||||
),
|
||||
"light": RpcEntityDescription(
|
||||
RpcEntityDescription(
|
||||
key="light",
|
||||
components=("light",),
|
||||
sub_key="output",
|
||||
entity_class=RpcShellyLight,
|
||||
),
|
||||
"cct": RpcEntityDescription(
|
||||
RpcEntityDescription(
|
||||
key="cct",
|
||||
components=("cct",),
|
||||
sub_key="output",
|
||||
entity_class=RpcShellyCctLight,
|
||||
),
|
||||
"rgb": RpcEntityDescription(
|
||||
RpcEntityDescription(
|
||||
key="rgb",
|
||||
components=("rgb",),
|
||||
sub_key="output",
|
||||
entity_class=RpcShellyRgbLight,
|
||||
),
|
||||
"rgbcct": RpcEntityDescription(
|
||||
RpcEntityDescription(
|
||||
key="rgbcct",
|
||||
components=("rgbcct",),
|
||||
sub_key="output",
|
||||
entity_class=RpcShellyRgbCctLight,
|
||||
),
|
||||
"rgbw": RpcEntityDescription(
|
||||
RpcEntityDescription(
|
||||
key="rgbw",
|
||||
components=("rgbw",),
|
||||
sub_key="output",
|
||||
entity_class=RpcShellyRgbwLight,
|
||||
),
|
||||
"ledstrip": RpcEntityDescription(
|
||||
RpcEntityDescription(
|
||||
key="ledstrip",
|
||||
components=("ledstrip",),
|
||||
sub_key="on",
|
||||
translation_key="ledstrip",
|
||||
entity_class=RpcShellyLedStrip,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@callback
|
||||
|
||||
@@ -56,12 +56,13 @@ class RpcMediaPlayerDescription(RpcEntityDescription, MediaPlayerEntityDescripti
|
||||
"""Class to describe a Shelly RPC media player entity."""
|
||||
|
||||
|
||||
RPC_MEDIA_PLAYER_ENTITIES: Final = {
|
||||
"media": RpcMediaPlayerDescription(
|
||||
RPC_MEDIA_PLAYER_ENTITIES: Final = (
|
||||
RpcMediaPlayerDescription(
|
||||
key="media",
|
||||
components=("media",),
|
||||
device_class=MediaPlayerDeviceClass.SPEAKER,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -219,9 +219,10 @@ BLOCK_NUMBERS: dict[tuple[str, str], BlockNumberDescription] = {
|
||||
}
|
||||
|
||||
|
||||
RPC_NUMBERS: Final = {
|
||||
"external_temperature": RpcNumberDescription(
|
||||
key="blutrv",
|
||||
RPC_NUMBERS: Final = (
|
||||
RpcNumberDescription(
|
||||
key="external_temperature",
|
||||
components=("blutrv",),
|
||||
sub_key="current_C",
|
||||
translation_key="external_temperature",
|
||||
native_min_value=-50,
|
||||
@@ -234,8 +235,9 @@ RPC_NUMBERS: Final = {
|
||||
method="blu_trv_set_external_temperature",
|
||||
entity_class=RpcBluTrvExtTempNumber,
|
||||
),
|
||||
"number_generic": RpcNumberDescription(
|
||||
key="number",
|
||||
RpcNumberDescription(
|
||||
key="number_generic",
|
||||
components=("number",),
|
||||
sub_key="value",
|
||||
removal_condition=lambda config, _, key: (
|
||||
not is_view_for_platform(config, key, NUMBER_DOMAIN)
|
||||
@@ -250,8 +252,9 @@ RPC_NUMBERS: Final = {
|
||||
method="number_set",
|
||||
role=ROLE_GENERIC,
|
||||
),
|
||||
"number_current_limit": RpcNumberDescription(
|
||||
key="number",
|
||||
RpcNumberDescription(
|
||||
key="number_current_limit",
|
||||
components=("number",),
|
||||
sub_key="value",
|
||||
translation_key="current_limit",
|
||||
device_class=NumberDeviceClass.CURRENT,
|
||||
@@ -264,8 +267,9 @@ RPC_NUMBERS: Final = {
|
||||
role="current_limit",
|
||||
models={MODEL_TOP_EV_CHARGER_EVE01},
|
||||
),
|
||||
"number_position": RpcNumberDescription(
|
||||
key="number",
|
||||
RpcNumberDescription(
|
||||
key="number_position",
|
||||
components=("number",),
|
||||
sub_key="value",
|
||||
translation_key="valve_position",
|
||||
entity_registry_enabled_default=False,
|
||||
@@ -278,8 +282,9 @@ RPC_NUMBERS: Final = {
|
||||
role="position",
|
||||
models={MODEL_FRANKEVER_WATER_VALVE},
|
||||
),
|
||||
"number_target_humidity": RpcNumberDescription(
|
||||
key="number",
|
||||
RpcNumberDescription(
|
||||
key="number_target_humidity",
|
||||
components=("number",),
|
||||
sub_key="value",
|
||||
translation_key="target_humidity",
|
||||
device_class=NumberDeviceClass.HUMIDITY,
|
||||
@@ -293,8 +298,9 @@ RPC_NUMBERS: Final = {
|
||||
role="target_humidity",
|
||||
models={MODEL_LINKEDGO_ST802_THERMOSTAT, MODEL_LINKEDGO_ST1820_THERMOSTAT},
|
||||
),
|
||||
"number_target_temperature": RpcNumberDescription(
|
||||
key="number",
|
||||
RpcNumberDescription(
|
||||
key="number_target_temperature",
|
||||
components=("number",),
|
||||
sub_key="value",
|
||||
translation_key="target_temperature",
|
||||
device_class=NumberDeviceClass.TEMPERATURE,
|
||||
@@ -308,8 +314,9 @@ RPC_NUMBERS: Final = {
|
||||
role="target_temperature",
|
||||
models={MODEL_LINKEDGO_ST802_THERMOSTAT, MODEL_LINKEDGO_ST1820_THERMOSTAT},
|
||||
),
|
||||
"valve_position": RpcNumberDescription(
|
||||
key="blutrv",
|
||||
RpcNumberDescription(
|
||||
key="valve_position",
|
||||
components=("blutrv",),
|
||||
sub_key="pos",
|
||||
translation_key="valve_position",
|
||||
native_min_value=0,
|
||||
@@ -323,8 +330,9 @@ RPC_NUMBERS: Final = {
|
||||
),
|
||||
entity_class=RpcBluTrvNumber,
|
||||
),
|
||||
"left_slot_intensity": RpcNumberDescription(
|
||||
key="cury",
|
||||
RpcNumberDescription(
|
||||
key="left_slot_intensity",
|
||||
components=("cury",),
|
||||
sub_key="slots",
|
||||
translation_key="left_slot_intensity",
|
||||
value=lambda status, _: status["left"]["intensity"],
|
||||
@@ -341,8 +349,9 @@ RPC_NUMBERS: Final = {
|
||||
),
|
||||
entity_class=RpcCuryIntensityNumber,
|
||||
),
|
||||
"right_slot_intensity": RpcNumberDescription(
|
||||
key="cury",
|
||||
RpcNumberDescription(
|
||||
key="right_slot_intensity",
|
||||
components=("cury",),
|
||||
sub_key="slots",
|
||||
translation_key="right_slot_intensity",
|
||||
value=lambda status, _: status["right"]["intensity"],
|
||||
@@ -359,8 +368,9 @@ RPC_NUMBERS: Final = {
|
||||
),
|
||||
entity_class=RpcCuryIntensityNumber,
|
||||
),
|
||||
"ledstrip_speed": RpcNumberDescription(
|
||||
key="ledstrip",
|
||||
RpcNumberDescription(
|
||||
key="ledstrip_speed",
|
||||
components=("ledstrip",),
|
||||
sub_key="speed",
|
||||
translation_key="effect_speed",
|
||||
native_min_value=0,
|
||||
@@ -372,8 +382,9 @@ RPC_NUMBERS: Final = {
|
||||
supported=lambda _: True,
|
||||
entity_class=RpcLedStripNumber,
|
||||
),
|
||||
"ledstrip_intensity": RpcNumberDescription(
|
||||
key="ledstrip",
|
||||
RpcNumberDescription(
|
||||
key="ledstrip_intensity",
|
||||
components=("ledstrip",),
|
||||
sub_key="intensity",
|
||||
translation_key="effect_intensity",
|
||||
native_min_value=0,
|
||||
@@ -385,7 +396,7 @@ RPC_NUMBERS: Final = {
|
||||
supported=lambda _: True,
|
||||
entity_class=RpcLedStripNumber,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -174,9 +174,10 @@ class RpcUiLedModeSelect(RpcSelect):
|
||||
await method({"leds": {"mode": option}})
|
||||
|
||||
|
||||
RPC_SELECT_ENTITIES: Final = {
|
||||
"cury_mode": RpcSelectDescription(
|
||||
key="cury",
|
||||
RPC_SELECT_ENTITIES: Final = (
|
||||
RpcSelectDescription(
|
||||
key="cury_mode",
|
||||
components=("cury",),
|
||||
sub_key="mode",
|
||||
translation_key="cury_mode",
|
||||
options=[
|
||||
@@ -191,8 +192,9 @@ RPC_SELECT_ENTITIES: Final = {
|
||||
method="cury_set_mode",
|
||||
entity_class=RpcCuryModeSelect,
|
||||
),
|
||||
"enum_generic": RpcSelectDescription(
|
||||
key="enum",
|
||||
RpcSelectDescription(
|
||||
key="enum_generic",
|
||||
components=("enum",),
|
||||
sub_key="value",
|
||||
removal_condition=lambda config, _status, key: (
|
||||
not is_view_for_platform(config, key, SELECT_DOMAIN)
|
||||
@@ -200,16 +202,18 @@ RPC_SELECT_ENTITIES: Final = {
|
||||
method="enum_set",
|
||||
role=ROLE_GENERIC,
|
||||
),
|
||||
"ledstrip_palette": RpcSelectDescription(
|
||||
key="ledstrip",
|
||||
RpcSelectDescription(
|
||||
key="ledstrip_palette",
|
||||
components=("ledstrip",),
|
||||
sub_key="palette",
|
||||
translation_key="effect_palette",
|
||||
method="ledstrip_set",
|
||||
supported=lambda _: True,
|
||||
entity_class=RpcLedStripPaletteSelect,
|
||||
),
|
||||
"plugs_ui_led_mode": RpcSelectDescription(
|
||||
key="plugs_ui",
|
||||
RpcSelectDescription(
|
||||
key="plugs_ui_led_mode",
|
||||
components=("plugs_ui",),
|
||||
translation_key="led_mode",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
options=["power", "switch", "off"],
|
||||
@@ -217,8 +221,9 @@ RPC_SELECT_ENTITIES: Final = {
|
||||
supported=lambda _: True,
|
||||
entity_class=RpcUiLedModeSelect,
|
||||
),
|
||||
"powerstrip_ui_led_mode": RpcSelectDescription(
|
||||
key="powerstrip_ui",
|
||||
RpcSelectDescription(
|
||||
key="powerstrip_ui_led_mode",
|
||||
components=("powerstrip_ui",),
|
||||
translation_key="led_mode",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
options=["power", "switch", "off"],
|
||||
@@ -226,7 +231,7 @@ RPC_SELECT_ENTITIES: Final = {
|
||||
supported=lambda _: True,
|
||||
entity_class=RpcUiLedModeSelect,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -243,9 +243,10 @@ class RpcLedStripSwitch(RpcSwitch):
|
||||
)
|
||||
|
||||
|
||||
RPC_SWITCHES = {
|
||||
"switch": RpcSwitchDescription(
|
||||
RPC_SWITCHES = (
|
||||
RpcSwitchDescription(
|
||||
key="switch",
|
||||
components=("switch",),
|
||||
sub_key="output",
|
||||
removal_condition=is_rpc_exclude_from_relay,
|
||||
is_on=lambda status: bool(status["output"]),
|
||||
@@ -254,8 +255,9 @@ RPC_SWITCHES = {
|
||||
method_params_fn=lambda id, value: (id, value),
|
||||
entity_class=RpcRelaySwitch,
|
||||
),
|
||||
"cb": RpcSwitchDescription(
|
||||
RpcSwitchDescription(
|
||||
key="cb",
|
||||
components=("cb",),
|
||||
sub_key="output",
|
||||
is_on=lambda status: bool(status["output"]),
|
||||
method_on="cb_set",
|
||||
@@ -263,8 +265,9 @@ RPC_SWITCHES = {
|
||||
method_params_fn=lambda id, value: (id, value),
|
||||
entity_class=RpcCircuitBreakerSwitch,
|
||||
),
|
||||
"boolean_generic": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_generic",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
removal_condition=lambda config, _, key: (
|
||||
not is_view_for_platform(config, key, SWITCH_DOMAIN)
|
||||
@@ -275,8 +278,9 @@ RPC_SWITCHES = {
|
||||
method_params_fn=lambda id, value: (id, value),
|
||||
role=ROLE_GENERIC,
|
||||
),
|
||||
"boolean_anti_freeze": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_anti_freeze",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="frost_protection",
|
||||
entity_registry_enabled_default=False,
|
||||
@@ -287,8 +291,9 @@ RPC_SWITCHES = {
|
||||
role="anti_freeze",
|
||||
models={MODEL_LINKEDGO_ST802_THERMOSTAT, MODEL_LINKEDGO_ST1820_THERMOSTAT},
|
||||
),
|
||||
"boolean_child_lock": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_child_lock",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="child_lock",
|
||||
is_on=lambda status: bool(status["value"]),
|
||||
@@ -298,8 +303,9 @@ RPC_SWITCHES = {
|
||||
role="child_lock",
|
||||
models={MODEL_LINKEDGO_ST1820_THERMOSTAT},
|
||||
),
|
||||
"boolean_enable": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_enable",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="thermostat_enabled",
|
||||
entity_registry_enabled_default=False,
|
||||
@@ -310,8 +316,9 @@ RPC_SWITCHES = {
|
||||
role="enable",
|
||||
models={MODEL_LINKEDGO_ST802_THERMOSTAT, MODEL_LINKEDGO_ST1820_THERMOSTAT},
|
||||
),
|
||||
"boolean_start_charging": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_start_charging",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="charging",
|
||||
is_on=lambda status: bool(status["value"]),
|
||||
@@ -321,8 +328,9 @@ RPC_SWITCHES = {
|
||||
role="start_charging",
|
||||
models={MODEL_TOP_EV_CHARGER_EVE01},
|
||||
),
|
||||
"boolean_state": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_state",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="valve_opened",
|
||||
entity_registry_enabled_default=False,
|
||||
@@ -333,8 +341,9 @@ RPC_SWITCHES = {
|
||||
role="state",
|
||||
models={MODEL_NEO_WATER_VALVE},
|
||||
),
|
||||
"boolean_zone0": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_zone0",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="zone_with_number",
|
||||
translation_placeholders={"zone_number": "1"},
|
||||
@@ -346,8 +355,9 @@ RPC_SWITCHES = {
|
||||
role="zone0",
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone1": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_zone1",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="zone_with_number",
|
||||
translation_placeholders={"zone_number": "2"},
|
||||
@@ -359,8 +369,9 @@ RPC_SWITCHES = {
|
||||
role="zone1",
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone2": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_zone2",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="zone_with_number",
|
||||
translation_placeholders={"zone_number": "3"},
|
||||
@@ -372,8 +383,9 @@ RPC_SWITCHES = {
|
||||
role="zone2",
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone3": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_zone3",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="zone_with_number",
|
||||
translation_placeholders={"zone_number": "4"},
|
||||
@@ -385,8 +397,9 @@ RPC_SWITCHES = {
|
||||
role="zone3",
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone4": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_zone4",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="zone_with_number",
|
||||
translation_placeholders={"zone_number": "5"},
|
||||
@@ -398,8 +411,9 @@ RPC_SWITCHES = {
|
||||
role="zone4",
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone5": RpcSwitchDescription(
|
||||
key="boolean",
|
||||
RpcSwitchDescription(
|
||||
key="boolean_zone5",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
translation_key="zone_with_number",
|
||||
translation_placeholders={"zone_number": "6"},
|
||||
@@ -411,8 +425,9 @@ RPC_SWITCHES = {
|
||||
role="zone5",
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"script": RpcSwitchDescription(
|
||||
RpcSwitchDescription(
|
||||
key="script",
|
||||
components=("script",),
|
||||
sub_key="running",
|
||||
is_on=lambda status: bool(status["running"]),
|
||||
method_on="script_start",
|
||||
@@ -421,8 +436,9 @@ RPC_SWITCHES = {
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
"cury_left": RpcSwitchDescription(
|
||||
key="cury",
|
||||
RpcSwitchDescription(
|
||||
key="cury_left",
|
||||
components=("cury",),
|
||||
sub_key="slots",
|
||||
translation_key="left_slot",
|
||||
is_on=lambda status: bool(status["slots"]["left"]["on"]),
|
||||
@@ -434,8 +450,9 @@ RPC_SWITCHES = {
|
||||
and left.get("vial", {}).get("level", -1) != -1
|
||||
),
|
||||
),
|
||||
"cury_left_boost": RpcSwitchDescription(
|
||||
key="cury",
|
||||
RpcSwitchDescription(
|
||||
key="cury_left_boost",
|
||||
components=("cury",),
|
||||
sub_key="slots",
|
||||
translation_key="left_slot_boost",
|
||||
is_on=lambda status: status["slots"]["left"]["boost"] is not None,
|
||||
@@ -447,8 +464,9 @@ RPC_SWITCHES = {
|
||||
and left.get("vial", {}).get("level", -1) != -1
|
||||
),
|
||||
),
|
||||
"cury_right": RpcSwitchDescription(
|
||||
key="cury",
|
||||
RpcSwitchDescription(
|
||||
key="cury_right",
|
||||
components=("cury",),
|
||||
sub_key="slots",
|
||||
translation_key="right_slot",
|
||||
is_on=lambda status: bool(status["slots"]["right"]["on"]),
|
||||
@@ -460,8 +478,9 @@ RPC_SWITCHES = {
|
||||
and right.get("vial", {}).get("level", -1) != -1
|
||||
),
|
||||
),
|
||||
"cury_right_boost": RpcSwitchDescription(
|
||||
key="cury",
|
||||
RpcSwitchDescription(
|
||||
key="cury_right_boost",
|
||||
components=("cury",),
|
||||
sub_key="slots",
|
||||
translation_key="right_slot_boost",
|
||||
is_on=lambda status: status["slots"]["right"]["boost"] is not None,
|
||||
@@ -473,8 +492,9 @@ RPC_SWITCHES = {
|
||||
and right.get("vial", {}).get("level", -1) != -1
|
||||
),
|
||||
),
|
||||
"cury_away_mode": RpcSwitchDescription(
|
||||
key="cury",
|
||||
RpcSwitchDescription(
|
||||
key="cury_away_mode",
|
||||
components=("cury",),
|
||||
sub_key="away_mode",
|
||||
translation_key="cury_away_mode",
|
||||
is_on=lambda status: status["away_mode"],
|
||||
@@ -482,8 +502,9 @@ RPC_SWITCHES = {
|
||||
method_off="cury_set_away_mode",
|
||||
method_params_fn=lambda id, value: (id, value),
|
||||
),
|
||||
"fan_boost": RpcSwitchDescription(
|
||||
key="fan",
|
||||
RpcSwitchDescription(
|
||||
key="fan_boost",
|
||||
components=("fan",),
|
||||
sub_key="boost",
|
||||
translation_key="boost",
|
||||
is_on=lambda status: status["boost"]["active"],
|
||||
@@ -492,8 +513,9 @@ RPC_SWITCHES = {
|
||||
method_params_fn=lambda id, _: (id,),
|
||||
entity_class=RpcFanBoostSwitch,
|
||||
),
|
||||
"ledstrip_reverse": RpcSwitchDescription(
|
||||
key="ledstrip",
|
||||
RpcSwitchDescription(
|
||||
key="ledstrip_reverse",
|
||||
components=("ledstrip",),
|
||||
sub_key="reverse",
|
||||
translation_key="effect_reverse",
|
||||
is_on=lambda status: bool(status["reverse"]),
|
||||
@@ -503,8 +525,8 @@ RPC_SWITCHES = {
|
||||
supported=lambda _: True,
|
||||
entity_class=RpcLedStripSwitch,
|
||||
),
|
||||
"in_locked": RpcSwitchDescription(
|
||||
key="switch",
|
||||
RpcSwitchDescription(
|
||||
key="in_locked",
|
||||
components=("switch", "cover"),
|
||||
translation_key="input_lock",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
@@ -516,8 +538,9 @@ RPC_SWITCHES = {
|
||||
method_params_fn=lambda id, value: (id, {"in_locked": value}),
|
||||
entity_class=RpcConfigSwitch,
|
||||
),
|
||||
"camera_privacy": RpcSwitchDescription(
|
||||
key="camera",
|
||||
RpcSwitchDescription(
|
||||
key="camera_privacy",
|
||||
components=("camera",),
|
||||
sub_key="privacy",
|
||||
translation_key="camera_privacy",
|
||||
is_on=lambda status: status["privacy"],
|
||||
@@ -526,7 +549,7 @@ RPC_SWITCHES = {
|
||||
method_params_fn=lambda id, value: (id, value),
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -37,16 +37,17 @@ class RpcTextDescription(RpcEntityDescription, TextEntityDescription):
|
||||
"""Class to describe a RPC text entity."""
|
||||
|
||||
|
||||
RPC_TEXT_ENTITIES: Final = {
|
||||
"text_generic": RpcTextDescription(
|
||||
key="text",
|
||||
RPC_TEXT_ENTITIES: Final = (
|
||||
RpcTextDescription(
|
||||
key="text_generic",
|
||||
components=("text",),
|
||||
sub_key="value",
|
||||
removal_condition=lambda config, _status, key: (
|
||||
not is_view_for_platform(config, key, TEXT_DOMAIN)
|
||||
),
|
||||
role=ROLE_GENERIC,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -315,17 +315,19 @@ class RpcBluTrvUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):
|
||||
)
|
||||
|
||||
|
||||
RPC_UPDATES: Final = {
|
||||
"fwupdate": RpcUpdateDescription(
|
||||
key="sys",
|
||||
RPC_UPDATES: Final = (
|
||||
RpcUpdateDescription(
|
||||
key="fwupdate",
|
||||
components=("sys",),
|
||||
sub_key="available_updates",
|
||||
latest_version=lambda status: status.get("stable", {"version": ""})["version"],
|
||||
beta=False,
|
||||
device_class=UpdateDeviceClass.FIRMWARE,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
"fwupdate_beta": RpcUpdateDescription(
|
||||
key="sys",
|
||||
RpcUpdateDescription(
|
||||
key="fwupdate_beta",
|
||||
components=("sys",),
|
||||
sub_key="available_updates",
|
||||
translation_key="beta_firmware",
|
||||
latest_version=lambda status: status.get("beta", {"version": ""})["version"],
|
||||
@@ -334,8 +336,9 @@ RPC_UPDATES: Final = {
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
"loraupdate": RpcUpdateDescription(
|
||||
key="lora",
|
||||
RpcUpdateDescription(
|
||||
key="loraupdate",
|
||||
components=("lora",),
|
||||
translation_key="lora_firmware",
|
||||
# Right after firmware update, lora status can be None
|
||||
latest_version=lambda status: status or {},
|
||||
@@ -344,14 +347,15 @@ RPC_UPDATES: Final = {
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
entity_class=RpcLoraAddOnUpdateEntity,
|
||||
),
|
||||
"blutrv_fwupdate": RpcBluTrvUpdateDescription(
|
||||
key="blutrv",
|
||||
RpcBluTrvUpdateDescription(
|
||||
key="blutrv_fwupdate",
|
||||
components=("blutrv",),
|
||||
sub_key="fw_ver",
|
||||
device_class=UpdateDeviceClass.FIRMWARE,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
entity_class=RpcBluTrvUpdateEntity,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -119,64 +119,72 @@ class RpcShellySimpleWaterValve(RpcShellyBaseWaterValve):
|
||||
await self.coordinator.device.boolean_set(self._id, False)
|
||||
|
||||
|
||||
RPC_VALVES: dict[str, RpcValveDescription] = {
|
||||
"water_valve": RpcValveDescription(
|
||||
key="number",
|
||||
RPC_VALVES: tuple[RpcValveDescription, ...] = (
|
||||
RpcValveDescription(
|
||||
key="water_valve",
|
||||
components=("number",),
|
||||
sub_key="value",
|
||||
role="position",
|
||||
entity_class=RpcShellyWaterValve,
|
||||
models={MODEL_FRANKEVER_WATER_VALVE},
|
||||
),
|
||||
"neo_water_valve": RpcValveDescription(
|
||||
key="boolean",
|
||||
RpcValveDescription(
|
||||
key="neo_water_valve",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
role="state",
|
||||
entity_class=RpcShellySimpleWaterValve,
|
||||
models={MODEL_NEO_WATER_VALVE},
|
||||
),
|
||||
"boolean_zone0": RpcValveDescription(
|
||||
key="boolean",
|
||||
RpcValveDescription(
|
||||
key="boolean_zone0",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
role="zone0",
|
||||
entity_class=RpcShellySimpleWaterValve,
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone1": RpcValveDescription(
|
||||
key="boolean",
|
||||
RpcValveDescription(
|
||||
key="boolean_zone1",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
role="zone1",
|
||||
entity_class=RpcShellySimpleWaterValve,
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone2": RpcValveDescription(
|
||||
key="boolean",
|
||||
RpcValveDescription(
|
||||
key="boolean_zone2",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
role="zone2",
|
||||
entity_class=RpcShellySimpleWaterValve,
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone3": RpcValveDescription(
|
||||
key="boolean",
|
||||
RpcValveDescription(
|
||||
key="boolean_zone3",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
role="zone3",
|
||||
entity_class=RpcShellySimpleWaterValve,
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone4": RpcValveDescription(
|
||||
key="boolean",
|
||||
RpcValveDescription(
|
||||
key="boolean_zone4",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
role="zone4",
|
||||
entity_class=RpcShellySimpleWaterValve,
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
"boolean_zone5": RpcValveDescription(
|
||||
key="boolean",
|
||||
RpcValveDescription(
|
||||
key="boolean_zone5",
|
||||
components=("boolean",),
|
||||
sub_key="value",
|
||||
role="zone5",
|
||||
entity_class=RpcShellySimpleWaterValve,
|
||||
models={MODEL_FRANKEVER_IRRIGATION_CONTROLLER},
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
"""Tests for Shelly entity helpers."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.shelly.binary_sensor import (
|
||||
RPC_SENSORS as RPC_BINARY_SENSORS,
|
||||
)
|
||||
from homeassistant.components.shelly.button import RPC_BUTTONS
|
||||
from homeassistant.components.shelly.camera import RPC_CAMERA_ENTITIES
|
||||
from homeassistant.components.shelly.climate import RPC_LINKEDGO_THERMOSTAT
|
||||
from homeassistant.components.shelly.cover import RPC_COVERS
|
||||
from homeassistant.components.shelly.entity import (
|
||||
RpcEntityDescription,
|
||||
get_rpc_descriptions_by_attribute,
|
||||
)
|
||||
from homeassistant.components.shelly.fan import RPC_FANS
|
||||
from homeassistant.components.shelly.infrared import RPC_INFRARED_ENTITIES
|
||||
from homeassistant.components.shelly.light import LIGHTS
|
||||
from homeassistant.components.shelly.media_player import RPC_MEDIA_PLAYER_ENTITIES
|
||||
from homeassistant.components.shelly.number import RPC_NUMBERS
|
||||
from homeassistant.components.shelly.select import RPC_SELECT_ENTITIES
|
||||
from homeassistant.components.shelly.sensor import RPC_SENSORS
|
||||
from homeassistant.components.shelly.switch import RPC_SWITCHES
|
||||
from homeassistant.components.shelly.text import RPC_TEXT_ENTITIES
|
||||
from homeassistant.components.shelly.update import RPC_UPDATES
|
||||
from homeassistant.components.shelly.valve import RPC_VALVES
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"descriptions",
|
||||
[
|
||||
pytest.param(RPC_BINARY_SENSORS, id="binary_sensor"),
|
||||
pytest.param(RPC_BUTTONS, id="button"),
|
||||
pytest.param(RPC_CAMERA_ENTITIES, id="camera"),
|
||||
pytest.param(RPC_LINKEDGO_THERMOSTAT, id="climate"),
|
||||
pytest.param(RPC_COVERS, id="cover"),
|
||||
pytest.param(RPC_FANS, id="fan"),
|
||||
pytest.param(RPC_INFRARED_ENTITIES, id="infrared"),
|
||||
pytest.param(LIGHTS, id="light"),
|
||||
pytest.param(RPC_MEDIA_PLAYER_ENTITIES, id="media_player"),
|
||||
pytest.param(RPC_NUMBERS, id="number"),
|
||||
pytest.param(RPC_SELECT_ENTITIES, id="select"),
|
||||
pytest.param(RPC_SENSORS, id="sensor"),
|
||||
pytest.param(RPC_SWITCHES, id="switch"),
|
||||
pytest.param(RPC_TEXT_ENTITIES, id="text"),
|
||||
pytest.param(RPC_UPDATES, id="update"),
|
||||
pytest.param(RPC_VALVES, id="valve"),
|
||||
],
|
||||
)
|
||||
def test_rpc_description_attributes_are_unique(
|
||||
descriptions: tuple[RpcEntityDescription, ...],
|
||||
) -> None:
|
||||
"""Test the keys and legacy IDs of a platform's RPC descriptions are unique."""
|
||||
by_attribute = get_rpc_descriptions_by_attribute(descriptions)
|
||||
|
||||
assert all(
|
||||
by_attribute[description.key] is description for description in descriptions
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"descriptions",
|
||||
[
|
||||
pytest.param(
|
||||
(
|
||||
RpcEntityDescription(key="power", components=("switch",)),
|
||||
RpcEntityDescription(key="power", components=("light",)),
|
||||
),
|
||||
id="key",
|
||||
),
|
||||
pytest.param(
|
||||
(
|
||||
RpcEntityDescription(key="power", components=("switch",)),
|
||||
RpcEntityDescription(
|
||||
key="power_pm1",
|
||||
components=("pm1", "light"),
|
||||
legacy_ids={"light": "power"},
|
||||
),
|
||||
),
|
||||
id="legacy_id",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_rpc_description_duplicate_attribute(
|
||||
descriptions: tuple[RpcEntityDescription, ...],
|
||||
) -> None:
|
||||
"""Test a key or legacy ID used by two RPC descriptions is rejected."""
|
||||
with pytest.raises(ValueError, match="Duplicate RPC description attribute: power"):
|
||||
get_rpc_descriptions_by_attribute(descriptions)
|
||||
Reference in New Issue
Block a user