From 167469b7d125b99b05ad2daa054e9d512bd8e908 Mon Sep 17 00:00:00 2001 From: Tomaae Date: Fri, 4 Feb 2022 22:30:44 +0100 Subject: [PATCH] added icons into types definition file for binary sensors --- custom_components/mikrotik_router/binary_sensor.py | 9 +++++++++ custom_components/mikrotik_router/binary_sensor_types.py | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/custom_components/mikrotik_router/binary_sensor.py b/custom_components/mikrotik_router/binary_sensor.py index 5d40878..ed4c15a 100644 --- a/custom_components/mikrotik_router/binary_sensor.py +++ b/custom_components/mikrotik_router/binary_sensor.py @@ -317,6 +317,15 @@ class MikrotikControllerBinarySensor(BinarySensorEntity): """Return true if device is on.""" return self._data[self.entity_description.data_is_on] + @property + def icon(self) -> str: + """Return the icon.""" + if self.entity_description.icon_enabled: + if self._data[self.entity_description.data_is_on]: + return self.entity_description.icon_enabled + else: + return self.entity_description.icon_disabled + @property def device_info(self) -> DeviceInfo: """Return a description for device registry.""" diff --git a/custom_components/mikrotik_router/binary_sensor_types.py b/custom_components/mikrotik_router/binary_sensor_types.py index bd10f39..c9a3ed3 100644 --- a/custom_components/mikrotik_router/binary_sensor_types.py +++ b/custom_components/mikrotik_router/binary_sensor_types.py @@ -15,6 +15,8 @@ from .const import DOMAIN class MikrotikBinarySensorEntityDescription(BinarySensorEntityDescription): """Class describing mikrotik entities.""" + icon_enabled: str = "" + icon_disabled: str = "" ha_group: str = "" ha_connection: str = "" ha_connection_value: str = "" @@ -30,7 +32,8 @@ SENSOR_TYPES = { "system_fwupdate": MikrotikBinarySensorEntityDescription( key="system_fwupdate", name="Firmware update", - icon="mdi:thermometer", + icon_enabled="", + icon_disabled="", device_class=BinarySensorDeviceClass.UPDATE, entity_category=EntityCategory.DIAGNOSTIC, ha_group="System",