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>
This commit is contained in:
John Hollowell 2024-05-07 15:43:01 -04:00 committed by GitHub
parent 649dd55da9
commit 640cd519dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 3 deletions

View File

@ -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,
),
)

View File

@ -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"
}
}
}
}