From 640cd519dd2dbd9ae3d98f405f1ba43bf00321fe Mon Sep 17 00:00:00 2001 From: John Hollowell Date: Tue, 7 May 2024 15:43:01 -0400 Subject: [PATCH] Add Venstar HVAC stage sensor (#107510) * Add sensor for which stage of heating/cooling is active for example, a 2-stage heating system would initially use the first stage for heat and if it was unable to fulfill the demand, the thermostat would call for the second stage heat in addition to the first stage heat already in use. * Add translation keys for english * Apply suggestions from code review Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> * Add translation of entity name * Update sensor name to correctly be translatable --------- Co-authored-by: Josef Zweck <24647999+zweckj@users.noreply.github.com> --- homeassistant/components/venstar/sensor.py | 20 ++++++++++++++++--- homeassistant/components/venstar/strings.json | 9 +++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/venstar/sensor.py b/homeassistant/components/venstar/sensor.py index 24b4b2f8b16..b4913a874d0 100644 --- a/homeassistant/components/venstar/sensor.py +++ b/homeassistant/components/venstar/sensor.py @@ -65,13 +65,15 @@ SCHEDULE_PARTS: dict[int, str] = { 255: "inactive", } +STAGES: dict[int, str] = {0: "idle", 1: "first_stage", 2: "second_stage"} + @dataclass(frozen=True, kw_only=True) class VenstarSensorEntityDescription(SensorEntityDescription): """Base description of a Sensor entity.""" value_fn: Callable[[VenstarDataUpdateCoordinator, str], Any] - name_fn: Callable[[str], str] + name_fn: Callable[[str], str] | None uom_fn: Callable[[Any], str | None] @@ -140,7 +142,8 @@ class VenstarSensor(VenstarEntity, SensorEntity): super().__init__(coordinator, config) self.entity_description = entity_description self.sensor_name = sensor_name - self._attr_name = entity_description.name_fn(sensor_name) + if entity_description.name_fn: + self._attr_name = entity_description.name_fn(sensor_name) self._config = config @property @@ -230,6 +233,17 @@ INFO_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = ( value_fn=lambda coordinator, sensor_name: SCHEDULE_PARTS[ coordinator.client.get_info(sensor_name) ], - name_fn=lambda _: "Schedule Part", + name_fn=None, + ), + VenstarSensorEntityDescription( + key="activestage", + device_class=SensorDeviceClass.ENUM, + options=list(STAGES.values()), + translation_key="active_stage", + uom_fn=lambda _: None, + value_fn=lambda coordinator, sensor_name: STAGES[ + coordinator.client.get_info(sensor_name) + ], + name_fn=None, ), ) diff --git a/homeassistant/components/venstar/strings.json b/homeassistant/components/venstar/strings.json index 92dfac211fb..952353dcbfe 100644 --- a/homeassistant/components/venstar/strings.json +++ b/homeassistant/components/venstar/strings.json @@ -26,6 +26,7 @@ "entity": { "sensor": { "schedule_part": { + "name": "Schedule Part", "state": { "morning": "Morning", "day": "Day", @@ -33,6 +34,14 @@ "night": "Night", "inactive": "Inactive" } + }, + "active_stage": { + "name": "Active stage", + "state": { + "idle": "Idle", + "first_stage": "First stage", + "second_stage": "Second stage" + } } } }