Add "Schedule Part" enum sensor to Venstar thermostat (#84332)
This commit is contained in:
parent
c181fb6de0
commit
174cc23309
3 changed files with 79 additions and 20 deletions
|
@ -56,6 +56,14 @@ RUNTIME_ATTRIBUTES = {
|
|||
RUNTIME_OV: "Override",
|
||||
}
|
||||
|
||||
SCHEDULE_PARTS: dict[int, str] = {
|
||||
0: "morning",
|
||||
1: "day",
|
||||
2: "evening",
|
||||
3: "night",
|
||||
255: "inactive",
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class VenstarSensorTypeMixin:
|
||||
|
@ -76,13 +84,11 @@ async def async_setup_entry(
|
|||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Vensar device binary_sensors based on a config entry."""
|
||||
"""Set up Venstar device sensors based on a config entry."""
|
||||
coordinator: VenstarDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
entities: list[Entity] = []
|
||||
|
||||
if not (sensors := coordinator.client.get_sensor_list()):
|
||||
return
|
||||
|
||||
if sensors := coordinator.client.get_sensor_list():
|
||||
for sensor_name in sensors:
|
||||
entities.extend(
|
||||
[
|
||||
|
@ -97,9 +103,22 @@ async def async_setup_entry(
|
|||
for sensor_name in runtimes:
|
||||
if sensor_name in RUNTIME_DEVICES:
|
||||
entities.append(
|
||||
VenstarSensor(coordinator, config_entry, RUNTIME_ENTITY, sensor_name)
|
||||
VenstarSensor(
|
||||
coordinator, config_entry, RUNTIME_ENTITY, sensor_name
|
||||
)
|
||||
)
|
||||
|
||||
for description in INFO_ENTITIES:
|
||||
try:
|
||||
# just checking if the key exists
|
||||
coordinator.client.get_info(description.key)
|
||||
except KeyError:
|
||||
continue
|
||||
entities.append(
|
||||
VenstarSensor(coordinator, config_entry, description, description.key)
|
||||
)
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
@ -210,3 +229,17 @@ RUNTIME_ENTITY = VenstarSensorEntityDescription(
|
|||
value_fn=lambda coordinator, sensor_name: coordinator.runtimes[-1][sensor_name],
|
||||
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {RUNTIME_ATTRIBUTES[sensor_name]} Runtime",
|
||||
)
|
||||
|
||||
INFO_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
|
||||
VenstarSensorEntityDescription(
|
||||
key="schedulepart",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=list(SCHEDULE_PARTS.values()),
|
||||
translation_key="schedule_part",
|
||||
uom_fn=lambda _: None,
|
||||
value_fn=lambda coordinator, sensor_name: SCHEDULE_PARTS[
|
||||
coordinator.client.get_info(sensor_name)
|
||||
],
|
||||
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} Schedule Part",
|
||||
),
|
||||
)
|
||||
|
|
|
@ -19,5 +19,18 @@
|
|||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"schedule_part": {
|
||||
"state": {
|
||||
"morning": "Morning",
|
||||
"day": "Day",
|
||||
"evening": "Evening",
|
||||
"night": "Night",
|
||||
"inactive": "Inactive"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,5 +19,18 @@
|
|||
"title": "Connect to the Venstar Thermostat"
|
||||
}
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"schedule_part": {
|
||||
"state": {
|
||||
"day": "Day",
|
||||
"evening": "Evening",
|
||||
"inactive": "Inactive",
|
||||
"morning": "Morning",
|
||||
"night": "Night"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue