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:
parent
e6c61f207d
commit
4ab3f1f41f
2 changed files with 40 additions and 6 deletions
|
@ -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",
|
||||
|
|
|
@ -25,6 +25,12 @@
|
|||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"filter_install_time": {
|
||||
"name": "Filter installation time"
|
||||
},
|
||||
"filter_usage": {
|
||||
"name": "Filter usage"
|
||||
},
|
||||
"schedule_part": {
|
||||
"name": "Schedule Part",
|
||||
"state": {
|
||||
|
|
Loading…
Add table
Reference in a new issue