Skip to content

Commit

Permalink
Added additional system cylinder temperature sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
signalkraft committed Feb 17, 2024
1 parent b2fa3c1 commit b4eb6ea
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 59 deletions.
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.17"
"myPyllant==0.7.18"
],
"version": "v0.7.3"
}
181 changes: 125 additions & 56 deletions custom_components/mypyllant/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ async def create_system_sensors(
)
if system.water_pressure is not None:
sensors.append(lambda: SystemWaterPressureSensor(index, system_coordinator))
if system.cylinder_temperature_sensor_top_dhw is not None:
sensors.append(
lambda: SystemTopDHWTemperatureSensor(index, system_coordinator)
)
if system.cylinder_temperature_sensor_bottom_dhw is not None:
sensors.append(
lambda: SystemBottomDHWTemperatureSensor(index, system_coordinator)
)
if system.cylinder_temperature_sensor_top_ch is not None:
sensors.append(
lambda: SystemTopCHTemperatureSensor(index, system_coordinator)
)
if system.cylinder_temperature_sensor_bottom_ch is not None:
sensors.append(
lambda: SystemBottomCHTemperatureSensor(index, system_coordinator)
)
sensors.append(lambda: HomeEntity(index, system_coordinator))

for device_index, device in enumerate(system.devices):
Expand Down Expand Up @@ -252,10 +268,99 @@ def name(self):
return f"{self.name_prefix} Outdoor Temperature"


class SystemTopDHWTemperatureSensor(SystemSensor):
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def native_value(self):
if self.system.cylinder_temperature_sensor_top_dhw is not None:
return round(self.system.cylinder_temperature_sensor_top_dhw, 1)
else:
return None

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_top_dhw_temperature"

@property
def name(self):
return f"{self.name_prefix} Top DHW Cylinder Temperature"


class SystemBottomDHWTemperatureSensor(SystemSensor):
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def native_value(self):
if self.system.cylinder_temperature_sensor_bottom_dhw is not None:
return round(self.system.cylinder_temperature_sensor_bottom_dhw, 1)
else:
return None

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_bottom_dhw_temperature"

@property
def name(self):
return f"{self.name_prefix} Bottom DHW Cylinder Temperature"


class SystemTopCHTemperatureSensor(SystemSensor):
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def native_value(self):
if self.system.cylinder_temperature_sensor_top_ch is not None:
return round(self.system.cylinder_temperature_sensor_top_ch, 1)
else:
return None

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_top_ch_temperature"

@property
def name(self):
return f"{self.name_prefix} Top Central Heating Cylinder Temperature"


class SystemBottomCHTemperatureSensor(SystemSensor):
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def native_value(self):
if self.system.cylinder_temperature_sensor_bottom_ch is not None:
return round(self.system.cylinder_temperature_sensor_bottom_ch, 1)
else:
return None

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_bottom_ch_temperature"

@property
def name(self):
return f"{self.name_prefix} Bottom Central Heating Cylinder Temperature"


class SystemWaterPressureSensor(SystemSensor):
_attr_native_unit_of_measurement = UnitOfPressure.BAR
_attr_device_class = SensorDeviceClass.PRESSURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def native_value(self):
Expand All @@ -268,16 +373,14 @@ def native_value(self):
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_water_pressure"

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} System Water Pressure"


class HomeEntity(CoordinatorEntity, SensorEntity):
_attr_entity_category = EntityCategory.DIAGNOSTIC

def __init__(
self,
system_index: int,
Expand All @@ -290,10 +393,6 @@ def __init__(
def system(self) -> System:
return self.coordinator.data[self.system_index]

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
return (
Expand Down Expand Up @@ -397,6 +496,8 @@ def unique_id(self) -> str:


class ZoneHeatingOperatingModeSensor(ZoneCoordinatorEntity, SensorEntity):
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} Heating Operating Mode"
Expand All @@ -409,12 +510,10 @@ def native_value(self):
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_heating_operating_mode"

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC


class ZoneHeatingStateSensor(ZoneCoordinatorEntity, SensorEntity):
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} Heating State"
Expand All @@ -430,12 +529,10 @@ def native_value(self):
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_heating_state"

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC


class ZoneCurrentSpecialFunctionSensor(ZoneCoordinatorEntity, SensorEntity):
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} Current Special Function"
Expand All @@ -448,10 +545,6 @@ def native_value(self):
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_current_special_function"

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC


class CircuitSensor(CoordinatorEntity, SensorEntity):
coordinator: SystemCoordinator
Expand Down Expand Up @@ -488,6 +581,7 @@ class CircuitFlowTemperatureSensor(CircuitSensor):
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
Expand All @@ -497,16 +591,14 @@ def name(self):
def native_value(self):
return self.circuit.current_circuit_flow_temperature

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_flow_temperature"


class CircuitStateSensor(CircuitSensor):
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} State"
Expand All @@ -515,10 +607,6 @@ def name(self):
def native_value(self):
return self.circuit.circuit_state

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
return prepare_field_value_for_dict(self.circuit.extra_fields)
Expand All @@ -532,6 +620,7 @@ class CircuitMinFlowTemperatureSetpointSensor(CircuitSensor):
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
Expand All @@ -541,17 +630,14 @@ def name(self):
def native_value(self):
return self.circuit.min_flow_temperature_setpoint

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_min_flow_temperature_setpoint"


class CircuitHeatingCurveSensor(CircuitSensor):
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
Expand All @@ -564,10 +650,6 @@ def native_value(self):
else:
return None

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_heating_curve"
Expand Down Expand Up @@ -614,6 +696,8 @@ def unique_id(self) -> str:
class DomesticHotWaterOperationModeSensor(
DomesticHotWaterCoordinatorEntity, SensorEntity
):
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} Operation Mode"
Expand All @@ -622,10 +706,6 @@ def name(self):
def native_value(self):
return self.domestic_hot_water.operation_mode_dhw.display_value

@property
def entity_category(self) -> EntityCategory:
return EntityCategory.DIAGNOSTIC

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_operation_mode"
Expand All @@ -634,6 +714,8 @@ def unique_id(self) -> str:
class DomesticHotWaterCurrentSpecialFunctionSensor(
DomesticHotWaterCoordinatorEntity, SensorEntity
):
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} Current Special Function"
Expand All @@ -642,10 +724,6 @@ def name(self):
def native_value(self):
return self.domestic_hot_water.current_special_function.display_value

@property
def entity_category(self) -> EntityCategory:
return EntityCategory.DIAGNOSTIC

@property
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_current_special_function"
Expand Down Expand Up @@ -908,6 +986,7 @@ class SystemDeviceWaterPressureSensor(SystemDeviceSensor):
_attr_native_unit_of_measurement = UnitOfPressure.BAR
_attr_device_class = SensorDeviceClass.PRESSURE
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def name(self):
Expand All @@ -921,15 +1000,12 @@ def native_value(self):
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_water_pressure"

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC


class SystemDeviceOperationTimeSensor(SystemDeviceSensor):
_attr_native_unit_of_measurement = UnitOfTime.HOURS
_attr_device_class = SensorDeviceClass.DURATION
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC

@property
def native_value(self):
Expand All @@ -942,17 +1018,14 @@ def native_value(self):
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_operation_time"

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} Operation Time"


class SystemDeviceOnOffCyclesSensor(SystemDeviceSensor):
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:counter"

@property
Expand All @@ -966,10 +1039,6 @@ def native_value(self):
def unique_id(self) -> str:
return f"{DOMAIN}_{self.id_infix}_on_off_cycles"

@property
def entity_category(self) -> EntityCategory | None:
return EntityCategory.DIAGNOSTIC

@property
def name(self):
return f"{self.name_prefix} On/Off Cycles"
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ types-PyYAML~=6.0.12.12
pytest==7.4.3
pytest-cov==4.1.0
pytest-homeassistant-custom-component==0.13.77
myPyllant==0.7.17
myPyllant==0.7.18
dacite~=1.7.0
Loading

0 comments on commit b4eb6ea

Please sign in to comment.