From 5c2c31898075f94cb62c0ffd41cc73cee0499c45 Mon Sep 17 00:00:00 2001 From: Tobias Thiemann Date: Tue, 13 Aug 2024 20:33:12 +0200 Subject: [PATCH 1/2] add online sensor --- custom_components/Estyma/binary_sensor.py | 73 ++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/custom_components/Estyma/binary_sensor.py b/custom_components/Estyma/binary_sensor.py index e708987..b055f9b 100755 --- a/custom_components/Estyma/binary_sensor.py +++ b/custom_components/Estyma/binary_sensor.py @@ -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 @@ -24,6 +28,7 @@ ATTR_language, ATTR_status_boiler_pump_sub1, ATTR_status_pump_heating_curcuit1_sub1, + ATTR_online, ) _LOGGER = logging.getLogger(__name__) @@ -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 @@ -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() From d2cb29e3c21ef10e36309cc0cf5ccde1b91e124c Mon Sep 17 00:00:00 2001 From: Tobias Thiemann Date: Tue, 13 Aug 2024 20:35:41 +0200 Subject: [PATCH 2/2] bump version --- custom_components/Estyma/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/Estyma/manifest.json b/custom_components/Estyma/manifest.json index 847aba0..1f82439 100755 --- a/custom_components/Estyma/manifest.json +++ b/custom_components/Estyma/manifest.json @@ -13,5 +13,5 @@ "EstymaApiWrapper==0.0.69", "beautifulsoup4==4.12.3" ], - "version": "1.0.7" + "version": "1.0.8" } \ No newline at end of file