Skip to content

Commit

Permalink
Eco preset only for time control heating operation mode, made entitiy…
Browse files Browse the repository at this point in the history
… initialization more robust and less likely to affect other entities on error
  • Loading branch information
signalkraft committed Feb 11, 2024
1 parent 31b15c4 commit e168740
Show file tree
Hide file tree
Showing 18 changed files with 387 additions and 61 deletions.
15 changes: 9 additions & 6 deletions custom_components/mypyllant/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from . import SystemCoordinator
from .const import DOMAIN
from .utils import EntityList

_LOGGER = logging.getLogger(__name__)

Expand All @@ -32,14 +33,16 @@ async def async_setup_entry(
_LOGGER.warning("No system data, skipping binary sensors")
return

sensors: list[BinarySensorEntity] = []
sensors: EntityList[BinarySensorEntity] = EntityList()
for index, system in enumerate(coordinator.data):
sensors.append(ControlError(index, coordinator))
sensors.append(ControlOnline(index, coordinator))
sensors.append(FirmwareUpdateRequired(index, coordinator))
sensors.append(FirmwareUpdateEnabled(index, coordinator))
sensors.append(lambda: ControlError(index, coordinator))
sensors.append(lambda: ControlOnline(index, coordinator))
sensors.append(lambda: FirmwareUpdateRequired(index, coordinator))
sensors.append(lambda: FirmwareUpdateEnabled(index, coordinator))
for circuit_index, circuit in enumerate(system.circuits):
sensors.append(CircuitIsCoolingAllowed(index, circuit_index, coordinator))
sensors.append(
lambda: CircuitIsCoolingAllowed(index, circuit_index, coordinator)
)

async_add_entities(sensors)

Expand Down
14 changes: 10 additions & 4 deletions custom_components/mypyllant/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@

from . import SystemCoordinator
from .const import DOMAIN, WEEKDAYS_TO_RFC5545, RFC5545_TO_WEEKDAYS
from .utils import ZoneCoordinatorEntity, DomesticHotWaterCoordinatorEntity
from .utils import (
ZoneCoordinatorEntity,
DomesticHotWaterCoordinatorEntity,
EntityList,
)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -43,12 +47,14 @@ async def async_setup_entry(
_LOGGER.warning("No system data, skipping calendar entities")
return

sensors: list[CalendarEntity] = []
sensors: EntityList[CalendarEntity] = EntityList()
for index, system in enumerate(coordinator.data):
for zone_index, zone in enumerate(system.zones):
sensors.append(ZoneHeatingCalendar(index, zone_index, coordinator))
sensors.append(lambda: ZoneHeatingCalendar(index, zone_index, coordinator))
for dhw_index, dhw in enumerate(system.domestic_hot_water):
sensors.append(DomesticHotWaterCalendar(index, dhw_index, coordinator))
sensors.append(
lambda: DomesticHotWaterCalendar(index, dhw_index, coordinator)
)
async_add_entities(sensors)


Expand Down
10 changes: 5 additions & 5 deletions custom_components/mypyllant/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
VentilationFanStageType,
)

from custom_components.mypyllant.utils import shorten_zone_name
from custom_components.mypyllant.utils import shorten_zone_name, EntityList

from . import SystemCoordinator
from .const import (
Expand Down Expand Up @@ -112,13 +112,13 @@ async def async_setup_entry(
_LOGGER.warning("No system data, skipping climate")
return

zone_entities: list[ClimateEntity] = []
ventilation_entities: list[ClimateEntity] = []
zone_entities: EntityList[ClimateEntity] = EntityList()
ventilation_entities: EntityList[ClimateEntity] = EntityList()

for index, system in enumerate(coordinator.data):
for zone_index, _ in enumerate(system.zones):
zone_entities.append(
ZoneClimate(
lambda: ZoneClimate(
index,
zone_index,
coordinator,
Expand All @@ -127,7 +127,7 @@ async def async_setup_entry(
)
for ventilation_index, _ in enumerate(system.ventilation):
ventilation_entities.append(
VentilationClimate(
lambda: VentilationClimate(
index,
ventilation_index,
coordinator,
Expand Down
12 changes: 8 additions & 4 deletions custom_components/mypyllant/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from custom_components.mypyllant import DOMAIN, SystemCoordinator
from custom_components.mypyllant.utils import HolidayEntity
from custom_components.mypyllant.utils import HolidayEntity, EntityList
from myPyllant.utils import get_default_holiday_dates

_LOGGER = logging.getLogger(__name__)
Expand All @@ -26,10 +26,14 @@ async def async_setup_entry(
_LOGGER.warning("No system data, skipping date time entities")
return

sensors = []
sensors: EntityList[DateTimeEntity] = EntityList()
for index, system in enumerate(coordinator.data):
sensors.append(SystemHolidayStartDateTimeEntity(index, coordinator, config))
sensors.append(SystemHolidayEndDateTimeEntity(index, coordinator, config))
sensors.append(
lambda: SystemHolidayStartDateTimeEntity(index, coordinator, config)
)
sensors.append(
lambda: SystemHolidayEndDateTimeEntity(index, coordinator, config)
)
async_add_entities(sensors)


Expand Down
2 changes: 1 addition & 1 deletion custom_components/mypyllant/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/signalkraft/mypyllant-component/issues",
"requirements": [
"myPyllant==0.7.12"
"myPyllant==0.7.13"
],
"version": "v0.7.3"
}
9 changes: 6 additions & 3 deletions custom_components/mypyllant/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
HolidayEntity,
SystemCoordinatorEntity,
ZoneCoordinatorEntity,
EntityList,
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -30,12 +31,14 @@ async def async_setup_entry(
_LOGGER.warning("No system data, skipping number entities")
return

sensors = []
sensors: EntityList[NumberEntity] = EntityList()
for index, system in enumerate(coordinator.data):
sensors.append(SystemHolidayDurationNumber(index, coordinator))
sensors.append(lambda: SystemHolidayDurationNumber(index, coordinator))

for zone_index, zone in enumerate(system.zones):
sensors.append(ZoneQuickVetoDurationNumber(index, zone_index, coordinator))
sensors.append(
lambda: ZoneQuickVetoDurationNumber(index, zone_index, coordinator)
)
async_add_entities(sensors)


Expand Down
75 changes: 47 additions & 28 deletions custom_components/mypyllant/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from collections.abc import Mapping
from typing import Any
from typing import Any, Iterable, Sequence

from homeassistant.components.sensor import (
SensorDeviceClass,
Expand Down Expand Up @@ -33,6 +33,7 @@
SystemCoordinatorEntity,
DomesticHotWaterCoordinatorEntity,
ZoneCoordinatorEntity,
EntityList,
)
from myPyllant.utils import prepare_field_value_for_dict

Expand All @@ -52,89 +53,101 @@

async def create_system_sensors(
hass: HomeAssistant, config: ConfigEntry
) -> list[SensorEntity]:
) -> Sequence[SensorEntity]:
system_coordinator: SystemCoordinator = hass.data[DOMAIN][config.entry_id][
"system_coordinator"
]
if not system_coordinator.data:
_LOGGER.warning("No system data, skipping sensors")
return []

sensors: list[SensorEntity] = []
sensors: EntityList[SensorEntity] = EntityList()
_LOGGER.debug("Creating system sensors for %s", system_coordinator.data)
for index, system in enumerate(system_coordinator.data):
if system.outdoor_temperature is not None:
sensors.append(SystemOutdoorTemperatureSensor(index, system_coordinator))
sensors.append(
lambda: SystemOutdoorTemperatureSensor(index, system_coordinator)
)
if system.water_pressure is not None:
sensors.append(SystemWaterPressureSensor(index, system_coordinator))
sensors.append(HomeEntity(index, system_coordinator))
sensors.append(lambda: SystemWaterPressureSensor(index, system_coordinator))
sensors.append(lambda: HomeEntity(index, system_coordinator))

for device_index, device in enumerate(system.devices):
_LOGGER.debug("Creating SystemDevice sensors for %s", device)

if "water_pressure" in device.operational_data:
sensors.append(
SystemDeviceWaterPressureSensor(
lambda: SystemDeviceWaterPressureSensor(
index, device_index, system_coordinator
)
)
if device.operation_time is not None:
sensors.append(
SystemDeviceOperationTimeSensor(
lambda: SystemDeviceOperationTimeSensor(
index, device_index, system_coordinator
)
)
if device.on_off_cycles is not None:
sensors.append(
SystemDeviceOnOffCyclesSensor(
lambda: SystemDeviceOnOffCyclesSensor(
index, device_index, system_coordinator
)
)

for zone_index, zone in enumerate(system.zones):
_LOGGER.debug("Creating Zone sensors for %s", zone)
sensors.append(
ZoneDesiredRoomTemperatureSetpointSensor(
lambda: ZoneDesiredRoomTemperatureSetpointSensor(
index, zone_index, system_coordinator
)
)
if zone.current_room_temperature is not None:
sensors.append(
ZoneCurrentRoomTemperatureSensor(
lambda: ZoneCurrentRoomTemperatureSensor(
index, zone_index, system_coordinator
)
)
if zone.current_room_humidity is not None:
sensors.append(
ZoneHumiditySensor(index, zone_index, system_coordinator)
lambda: ZoneHumiditySensor(index, zone_index, system_coordinator)
)
sensors.append(
ZoneHeatingOperatingModeSensor(index, zone_index, system_coordinator)
lambda: ZoneHeatingOperatingModeSensor(
index, zone_index, system_coordinator
)
)
if zone.heating_state is not None:
sensors.append(
ZoneHeatingStateSensor(index, zone_index, system_coordinator)
lambda: ZoneHeatingStateSensor(
index, zone_index, system_coordinator
)
)
sensors.append(
ZoneCurrentSpecialFunctionSensor(index, zone_index, system_coordinator)
lambda: ZoneCurrentSpecialFunctionSensor(
index, zone_index, system_coordinator
)
)

for circuit_index, circuit in enumerate(system.circuits):
_LOGGER.debug("Creating Circuit sensors for %s", circuit)
sensors.append(CircuitStateSensor(index, circuit_index, system_coordinator))
sensors.append(
lambda: CircuitStateSensor(index, circuit_index, system_coordinator)
)
if circuit.current_circuit_flow_temperature is not None:
sensors.append(
CircuitFlowTemperatureSensor(
lambda: CircuitFlowTemperatureSensor(
index, circuit_index, system_coordinator
)
)
if circuit.heating_curve is not None:
sensors.append(
CircuitHeatingCurveSensor(index, circuit_index, system_coordinator)
lambda: CircuitHeatingCurveSensor(
index, circuit_index, system_coordinator
)
)
if circuit.min_flow_temperature_setpoint is not None:
sensors.append(
CircuitMinFlowTemperatureSetpointSensor(
lambda: CircuitMinFlowTemperatureSetpointSensor(
index, circuit_index, system_coordinator
)
)
Expand All @@ -143,20 +156,22 @@ async def create_system_sensors(
_LOGGER.debug("Creating Domestic Hot Water sensors for %s", dhw)
if dhw.current_dhw_temperature:
sensors.append(
DomesticHotWaterTankTemperatureSensor(
lambda: DomesticHotWaterTankTemperatureSensor(
index, dhw_index, system_coordinator
)
)
sensors.append(
DomesticHotWaterSetPointSensor(index, dhw_index, system_coordinator)
lambda: DomesticHotWaterSetPointSensor(
index, dhw_index, system_coordinator
)
)
sensors.append(
DomesticHotWaterOperationModeSensor(
lambda: DomesticHotWaterOperationModeSensor(
index, dhw_index, system_coordinator
)
)
sensors.append(
DomesticHotWaterCurrentSpecialFunctionSensor(
lambda: DomesticHotWaterCurrentSpecialFunctionSensor(
index, dhw_index, system_coordinator
)
)
Expand All @@ -165,7 +180,7 @@ async def create_system_sensors(

async def create_daily_data_sensors(
hass: HomeAssistant, config: ConfigEntry
) -> list[SensorEntity]:
) -> Iterable[SensorEntity]:
daily_data_coordinator: DailyDataCoordinator = hass.data[DOMAIN][config.entry_id][
"daily_data_coordinator"
]
Expand All @@ -176,10 +191,12 @@ async def create_daily_data_sensors(
_LOGGER.warning("No daily data, skipping sensors")
return []

sensors: list[SensorEntity] = []
sensors: EntityList[SensorEntity] = EntityList()
for system_id, system_devices in daily_data_coordinator.data.items():
_LOGGER.debug("Creating efficiency sensor for System %s", system_id)
sensors.append(EfficiencySensor(system_id, None, daily_data_coordinator))
sensors.append(
lambda: EfficiencySensor(system_id, None, daily_data_coordinator)
)
for de_index, devices_data in enumerate(system_devices["devices_data"]):
if len(devices_data) == 0:
continue
Expand All @@ -189,13 +206,15 @@ async def create_daily_data_sensors(
de_index,
)
sensors.append(
EfficiencySensor(system_id, de_index, daily_data_coordinator)
lambda: EfficiencySensor(system_id, de_index, daily_data_coordinator)
)
for da_index, _ in enumerate(
daily_data_coordinator.data[system_id]["devices_data"][de_index]
):
sensors.append(
DataSensor(system_id, de_index, da_index, daily_data_coordinator)
lambda: DataSensor(
system_id, de_index, da_index, daily_data_coordinator
)
)

return sensors
Expand Down
9 changes: 6 additions & 3 deletions custom_components/mypyllant/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from custom_components.mypyllant.utils import (
HolidayEntity,
DomesticHotWaterCoordinatorEntity,
EntityList,
)
from myPyllant.utils import get_default_holiday_dates

Expand All @@ -28,12 +29,14 @@ async def async_setup_entry(
_LOGGER.warning("No system data, skipping switch entities")
return

sensors = []
sensors: EntityList[SwitchEntity] = EntityList()
for index, system in enumerate(coordinator.data):
sensors.append(SystemHolidaySwitch(index, coordinator, config))
sensors.append(lambda: SystemHolidaySwitch(index, coordinator, config))

for dhw_index, dhw in enumerate(system.domestic_hot_water):
sensors.append(DomesticHotWaterBoostSwitch(index, dhw_index, coordinator))
sensors.append(
lambda: DomesticHotWaterBoostSwitch(index, dhw_index, coordinator)
)
async_add_entities(sensors)


Expand Down
Loading

0 comments on commit e168740

Please sign in to comment.