Skip to content

Commit

Permalink
Merge pull request #14 from Tabisch/add/binary_sensor_online
Browse files Browse the repository at this point in the history
Add/binary sensor online
  • Loading branch information
Tabisch authored Oct 6, 2024
2 parents 81d5559 + d2cb29e commit 6420e87
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
73 changes: 72 additions & 1 deletion custom_components/Estyma/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from EstymaApiWrapper import EstymaApi
import voluptuous as vol

from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity
from homeassistant.components.binary_sensor import (
PLATFORM_SCHEMA,
BinarySensorEntity,
BinarySensorDeviceClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DEVICE_ID, CONF_EMAIL, CONF_PASSWORD
from homeassistant.core import HomeAssistant, callback
Expand All @@ -24,6 +28,7 @@
ATTR_language,
ATTR_status_boiler_pump_sub1,
ATTR_status_pump_heating_curcuit1_sub1,
ATTR_online,
)

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -74,6 +79,13 @@ async def setup(coordinator: CoordinatorEntity):
Device_Id=device_id,
)
)
sensors.append(
EstymaIsOnlineBinarySensor(
coordinator=coordinator,
deviceAttribute=ATTR_online,
Device_Id=device_id,
)
)

return sensors

Expand Down Expand Up @@ -159,3 +171,62 @@ def _handle_coordinator_update(self) -> None:
]

self.async_write_ha_state()


class EstymaIsOnlineBinarySensor(BinarySensorEntity, CoordinatorEntity):
def __init__(
self, coordinator: CoordinatorEntity, deviceAttribute, Device_Id
) -> None:
super().__init__(coordinator=coordinator)
self._name = f"{DOMAIN}_{Device_Id}_{deviceAttribute}"
self._attributename = deviceAttribute
self._attr_device_class = BinarySensorDeviceClass.CONNECTIVITY

self._state = self.coordinator.dataTextToValues[Device_Id][self._attributename]
self._available = True

self.attrs: dict[str, Any] = {
CONF_DEVICE_ID: Device_Id,
"last_update": "",
"last_update_diff": "",
}

@property
def name(self) -> str:
return self._name

# Todo automatic names
# @property
# def displayname(self):
# return "text"

@property
def unique_id(self) -> str:
return f"{self._name}"

@property
def is_on(self):
return self._state

@property
def device_info(self):
return {
"identifiers": {
# Serial numbers are unique identifiers within a specific domain
(DOMAIN, f"{DEFAULT_NAME}_{self.attrs[CONF_DEVICE_ID]}")
},
"name": f"{DEFAULT_NAME}_{self.attrs[CONF_DEVICE_ID]}",
"manufacturer": DEFAULT_NAME,
}

@callback
def _handle_coordinator_update(self) -> None:
_LOGGER.debug(
f"EstymaBinarySensor - {self._name} - {self.attrs[CONF_DEVICE_ID]} - {self.coordinator.data[self.attrs[CONF_DEVICE_ID]][self._attributename]}"
)

self._state = self.coordinator.dataTextToValues[self.attrs[CONF_DEVICE_ID]][
"online"
]["is_online"]

self.async_write_ha_state()
2 changes: 1 addition & 1 deletion custom_components/Estyma/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"EstymaApiWrapper==0.0.69",
"beautifulsoup4==4.12.3"
],
"version": "1.0.7"
"version": "1.0.8"
}

0 comments on commit 6420e87

Please sign in to comment.