Add Venstar air filter sensors (#115832)

* Add sensors for HVAC filter usage

The number of hours and the number of days are not linked.
The number of hours is a sum of the hours the filter has been in use (fan running). The days is just the number of days since the filter was reset.

* Update filter sensors' names

* Split consumables entity descriptions and move names to translations

* Scale filterHours to match real-world time

It looks like the integer returned by the thermostat is actually 100 times the number of hours.

* Address review comments/changes
This commit is contained in:
John Hollowell 2024-08-18 11:22:44 -04:00 committed by GitHub
parent e6c61f207d
commit 4ab3f1f41f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 6 deletions

View file

@ -75,7 +75,7 @@ class VenstarSensorEntityDescription(SensorEntityDescription):
value_fn: Callable[[VenstarDataUpdateCoordinator, str], Any]
name_fn: Callable[[str], str] | None
uom_fn: Callable[[Any], str | None]
uom_fn: Callable[[VenstarDataUpdateCoordinator], str | None]
async def async_setup_entry(
@ -99,11 +99,18 @@ async def async_setup_entry(
)
runtimes = coordinator.runtimes[-1]
entities.extend(
VenstarSensor(coordinator, config_entry, RUNTIME_ENTITY, sensor_name)
for sensor_name in runtimes
if sensor_name in RUNTIME_DEVICES
)
for sensor_name in runtimes:
if sensor_name in RUNTIME_DEVICES:
entities.append(
VenstarSensor(
coordinator, config_entry, RUNTIME_ENTITY, sensor_name
)
)
entities.extend(
VenstarSensor(coordinator, config_entry, description, sensor_name)
for description in CONSUMABLE_ENTITIES
if description.key == sensor_name
)
for description in INFO_ENTITIES:
try:
@ -224,6 +231,27 @@ RUNTIME_ENTITY = VenstarSensorEntityDescription(
name_fn=lambda sensor_name: f"{RUNTIME_ATTRIBUTES[sensor_name]} Runtime",
)
CONSUMABLE_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
VenstarSensorEntityDescription(
key="filterHours",
state_class=SensorStateClass.MEASUREMENT,
uom_fn=lambda _: UnitOfTime.HOURS,
value_fn=lambda coordinator, sensor_name: (
coordinator.runtimes[-1][sensor_name] / 100
),
name_fn=None,
translation_key="filter_install_time",
),
VenstarSensorEntityDescription(
key="filterDays",
state_class=SensorStateClass.MEASUREMENT,
uom_fn=lambda _: UnitOfTime.DAYS,
value_fn=lambda coordinator, sensor_name: coordinator.runtimes[-1][sensor_name],
name_fn=None,
translation_key="filter_usage",
),
)
INFO_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
VenstarSensorEntityDescription(
key="schedulepart",

View file

@ -25,6 +25,12 @@
},
"entity": {
"sensor": {
"filter_install_time": {
"name": "Filter installation time"
},
"filter_usage": {
"name": "Filter usage"
},
"schedule_part": {
"name": "Schedule Part",
"state": {