Skip to content

Commit

Permalink
Sensor showing if the heater is working
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgospodinow committed Nov 18, 2024
1 parent 419cf7f commit fe2153e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 7 deletions.
14 changes: 14 additions & 0 deletions custom_components/eldom/eldom_boiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def saved_energy(self) -> float:
def current_operation(self) -> str:
"""Return current operation ie. Off, Heating, Smart, or Study."""

@abstractmethod
def heater_enabled(self) -> bool:
"""Retrieve whether the boiler's heater is enabled."""

@abstractmethod
async def turn_on(self) -> None:
"""Turn the boiler on."""
Expand Down Expand Up @@ -208,6 +212,11 @@ def current_operation(self) -> str:
"""Return current operation ie. Off, Heating, Smart, or Study."""
return OPERATION_MODES.get(self._flat_boiler_details.State, "Unknown")

@property
def heater_enabled(self) -> bool:
"""Retrieve whether the boiler's heater is enabled."""
return self._flat_boiler_details.PowerFlag != 0

async def turn_on(self) -> None:
"""Turn the boiler on."""
await self.set_operation_mode(STATE_ECO)
Expand Down Expand Up @@ -338,6 +347,11 @@ def current_operation(self) -> str:
"""Return current operation ie. Off, Heating, Smart, or Study."""
return OPERATION_MODES.get(self._smart_boiler_details.State, "Unknown")

@property
def heater_enabled(self) -> bool:
"""Retrieve whether the boiler's heater is enabled."""
return self._smart_boiler_details.Heater

async def turn_on(self) -> None:
"""Turn the boiler on."""
await self.set_operation_mode(STATE_ECO)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/eldom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"requirements": ["pyeldom==0.3.0"],
"ssdp": [],
"zeroconf": [],
"version": "2.1.0"
"version": "2.2.0"
}
83 changes: 77 additions & 6 deletions custom_components/eldom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
SAVED_ENERGY_SENSOR_NAME = "Saved Energy"
SAVED_ENERGY_SENSOR_ICON = "mdi:lightning-bolt"

HEATER_SENSOR_NAME = "Heater"
HEATER_SENSOR_ICON = "mdi:heat-wave"
HEATER_STATE_ON = "On"
HEATER_STATE_OFF = "Off"


async def async_setup_entry(
hass: HomeAssistant,
Expand All @@ -52,6 +57,9 @@ async def async_setup_entry(
entities_to_add.append(
EldomBoilerSavedEnergySensor(flat_boiler, eldom_data.coordinator)
)
entities_to_add.append(
EldomBoilerHeaterSensor(flat_boiler, eldom_data.coordinator)
)

for smart_boiler in eldom_data.coordinator.data.get(
DEVICE_TYPE_SMART_BOILER
Expand All @@ -67,6 +75,9 @@ async def async_setup_entry(
entities_to_add.append(
EldomBoilerSavedEnergySensor(smart_boiler, eldom_data.coordinator)
)
entities_to_add.append(
EldomBoilerHeaterSensor(smart_boiler, eldom_data.coordinator)
)

async_add_entities(entities_to_add)

Expand Down Expand Up @@ -101,12 +112,12 @@ def name(self) -> str:

@property
def icon(self) -> str:
"""Return the icon of the powerful mode switch."""
"""Return the icon of the sensor."""
return DAY_ENERGY_CONSUMPTION_ICON

@property
def device_class(self) -> SensorDeviceClass:
"""Return the device class of the powerful mode switch."""
"""Return the device class of the sensor."""
return SensorDeviceClass.ENERGY

@property
Expand Down Expand Up @@ -159,12 +170,12 @@ def name(self) -> str:

@property
def icon(self) -> str:
"""Return the icon of the powerful mode switch."""
"""Return the icon of the sensor."""
return NIGHT_ENERGY_CONSUMPTION_ICON

@property
def device_class(self) -> SensorDeviceClass:
"""Return the device class of the powerful mode switch."""
"""Return the device class of the sensor."""
return SensorDeviceClass.ENERGY

@property
Expand Down Expand Up @@ -217,12 +228,12 @@ def name(self) -> str:

@property
def icon(self) -> str:
"""Return the icon of the powerful mode switch."""
"""Return the icon of the sensor."""
return SAVED_ENERGY_SENSOR_ICON

@property
def device_class(self) -> SensorDeviceClass:
"""Return the device class of the powerful mode switch."""
"""Return the device class of the sensor."""
return SensorDeviceClass.ENERGY

@property
Expand All @@ -243,3 +254,63 @@ def _handle_coordinator_update(self) -> None:
)

self.async_write_ha_state()


class EldomBoilerHeaterSensor(SensorEntity, CoordinatorEntity):
"""Representation of an Eldom boiler's heater."""

def __init__(
self, eldom_boiler: EldomBoiler, coordinator: EldomCoordinator
) -> None:
"""Initialize a sensor for an Eldom boiler's heater."""
super().__init__(coordinator)

self._eldom_boiler = eldom_boiler

@property
def device_info(self) -> DeviceInfo:
"""Return device information about this water heater."""
return DeviceInfo(
identifiers={(DOMAIN, self._eldom_boiler.device_id)},
)

@property
def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self._eldom_boiler.device_id}-heater-sensor"

@property
def name(self) -> str:
"""Return the name of the sensor."""
return f"{self._eldom_boiler.name}'s {HEATER_SENSOR_NAME}"

@property
def icon(self) -> str:
"""Return the icon of the heater sensor."""
return HEATER_SENSOR_ICON

@property
def device_class(self) -> SensorDeviceClass:
"""Return the device class of the sensor."""
return SensorDeviceClass.ENUM

@property
def options(self) -> list[str]:
"""Return a set of possible options."""
return [HEATER_STATE_ON, HEATER_STATE_OFF]

@property
def native_value(self) -> int:
"""Return the state of the sensor."""
return (
HEATER_STATE_ON if self._eldom_boiler.heater_enabled else HEATER_STATE_OFF
)

@callback
def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
self._eldom_boiler = self.coordinator.data.get(self._eldom_boiler.type).get(
self._eldom_boiler.id
)

self.async_write_ha_state()

0 comments on commit fe2153e

Please sign in to comment.