From ef8eab06ff9dc8388014223955c4721dc27a5f49 Mon Sep 17 00:00:00 2001 From: slajob Date: Tue, 5 Mar 2024 23:46:55 +0100 Subject: [PATCH] binary class windows probably missing to sensor working --- .../dirigera_platform/binary_sensor.py | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/custom_components/dirigera_platform/binary_sensor.py b/custom_components/dirigera_platform/binary_sensor.py index dee4e81..4658188 100644 --- a/custom_components/dirigera_platform/binary_sensor.py +++ b/custom_components/dirigera_platform/binary_sensor.py @@ -3,7 +3,10 @@ import dirigera from homeassistant import config_entries, core -from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.components.binary_sensor import ( + BinarySensorDeviceClass, + BinarySensorEntity, +) from homeassistant.const import CONF_IP_ADDRESS, CONF_TOKEN from homeassistant.core import HomeAssistantError from homeassistant.helpers.entity import DeviceInfo @@ -117,6 +120,28 @@ def __init__(self, hub, json_data): self._hub = hub self._json_data = json_data + @property + def device_info(self) -> DeviceInfo: + return DeviceInfo( + identifiers={("dirigera_platform", self._json_data.id)}, + name=self._json_data.attributes.custom_name, + manufacturer=self._json_data.attributes.manufacturer, + model=self._json_data.attributes.model, + sw_version=self._json_data.attributes.firmware_version, + ) + + @property + def device_class(self) -> str: + return BinarySensorDeviceClass.WINDOW + + @property + def name(self): + return self._json_data.attributes.custom_name + + @property + def is_on(self): + return self._json_data.attributes.is_open + def update(self): logger.debug("open close sensor update...") try: @@ -125,6 +150,3 @@ def update(self): logger.error("error encountered running update on : {}".format(self.name)) logger.error(ex) raise HomeAssistantError(ex, DOMAIN, "hub_exception") - - def is_on(self): - return self._json_data.attributes.is_open