From 16c2e91bbcb6f8ac877cd553ff80f516d63c0461 Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Sat, 21 Nov 2026 12:48:29 +0200 Subject: [PATCH] Store Shelly REST entity descriptions as tuples (#193664) Co-authored-by: Claude Fable 5.2 --- homeassistant/components/shelly/binary_sensor.py | 6 +++--- homeassistant/components/shelly/entity.py | 6 +++--- homeassistant/components/shelly/sensor.py | 8 ++++---- homeassistant/components/shelly/update.py | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/shelly/binary_sensor.py b/homeassistant/components/shelly/binary_sensor.py index 562c0a50c40e..a9bef9d106fe 100644 --- a/homeassistant/components/shelly/binary_sensor.py +++ b/homeassistant/components/shelly/binary_sensor.py @@ -219,8 +219,8 @@ BLOCK_SENSORS: dict[tuple[str, str], BlockBinarySensorDescription] = { ), } -REST_SENSORS: Final = { - "cloud": RestBinarySensorDescription( +REST_SENSORS: Final = ( + RestBinarySensorDescription( key="cloud", translation_key="cloud", value=lambda status, _: status["cloud"]["connected"], @@ -228,7 +228,7 @@ REST_SENSORS: Final = { entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, ), -} +) RPC_SENSORS: Final = ( RpcBinarySensorDescription( diff --git a/homeassistant/components/shelly/entity.py b/homeassistant/components/shelly/entity.py index c4768d92b3de..4c8df7f1f5a3 100644 --- a/homeassistant/components/shelly/entity.py +++ b/homeassistant/components/shelly/entity.py @@ -305,7 +305,7 @@ def async_setup_entry_rest( hass: HomeAssistant, config_entry: ShellyConfigEntry, async_add_entities: AddEntitiesCallback, - sensors: Mapping[str, RestEntityDescription], + sensors: Iterable[RestEntityDescription], sensor_class: Callable, ) -> None: """Set up entities for REST sensors.""" @@ -313,8 +313,8 @@ def async_setup_entry_rest( assert coordinator async_add_entities( - sensor_class(coordinator, sensor_id, sensors[sensor_id]) - for sensor_id in sensors + sensor_class(coordinator, description.key, description) + for description in sensors ) diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index fe9bd3669a37..447f28b69a60 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -520,8 +520,8 @@ BLOCK_SENSORS: dict[tuple[str, str], BlockSensorDescription] = { ), } -REST_SENSORS: Final = { - "rssi": RestSensorDescription( +REST_SENSORS: Final = ( + RestSensorDescription( key="rssi", native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, value=lambda status, _: status["wifi_sta"]["rssi"], @@ -530,14 +530,14 @@ REST_SENSORS: Final = { entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, ), - "uptime": RestSensorDescription( + RestSensorDescription( key="uptime", value=lambda status, _: utcnow() - timedelta(seconds=status["uptime"]), device_class=SensorDeviceClass.UPTIME, entity_registry_enabled_default=False, entity_category=EntityCategory.DIAGNOSTIC, ), -} +) RPC_SENSORS: Final = ( diff --git a/homeassistant/components/shelly/update.py b/homeassistant/components/shelly/update.py index efbdaa4aaaf1..63f9ab49b7b3 100644 --- a/homeassistant/components/shelly/update.py +++ b/homeassistant/components/shelly/update.py @@ -69,8 +69,8 @@ class RestUpdateDescription(RestEntityDescription, UpdateEntityDescription): beta: bool -REST_UPDATES: Final = { - "fwupdate": RestUpdateDescription( +REST_UPDATES: Final = ( + RestUpdateDescription( key="fwupdate", latest_version=lambda status: status["update"]["new_version"], beta=False, @@ -78,8 +78,8 @@ REST_UPDATES: Final = { entity_category=EntityCategory.CONFIG, entity_registry_enabled_default=False, ), - "fwupdate_beta": RestUpdateDescription( - key="fwupdate", + RestUpdateDescription( + key="fwupdate_beta", translation_key="beta_firmware", latest_version=lambda status: status["update"].get("beta_version"), beta=True, @@ -87,7 +87,7 @@ REST_UPDATES: Final = { entity_category=EntityCategory.CONFIG, entity_registry_enabled_default=False, ), -} +) class RpcLoraAddOnUpdateEntity(ShellyRpcAttributeEntity, UpdateEntity):