From 3f3727a8d450363bea80f7460d1b11483263247d Mon Sep 17 00:00:00 2001 From: Sanjoy Ghosh Date: Sat, 30 Mar 2024 12:26:15 +0530 Subject: [PATCH] Takes care of zero len custom_name --- custom_components/dirigera_platform/binary_sensor.py | 8 ++++++-- custom_components/dirigera_platform/cover.py | 4 +++- custom_components/dirigera_platform/fan.py | 4 +++- custom_components/dirigera_platform/light.py | 9 +++++---- custom_components/dirigera_platform/sensor.py | 8 ++++++-- custom_components/dirigera_platform/switch.py | 4 +++- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/custom_components/dirigera_platform/binary_sensor.py b/custom_components/dirigera_platform/binary_sensor.py index d17421a..57857eb 100644 --- a/custom_components/dirigera_platform/binary_sensor.py +++ b/custom_components/dirigera_platform/binary_sensor.py @@ -89,7 +89,7 @@ def available(self): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -97,6 +97,8 @@ def device_info(self) -> DeviceInfo: @property def name(self): + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name @property @@ -123,7 +125,7 @@ def __init__(self, hub, json_data): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -135,6 +137,8 @@ def device_class(self) -> str: @property def name(self): + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name @property diff --git a/custom_components/dirigera_platform/cover.py b/custom_components/dirigera_platform/cover.py index 4ce5d35..25ed88f 100644 --- a/custom_components/dirigera_platform/cover.py +++ b/custom_components/dirigera_platform/cover.py @@ -62,7 +62,7 @@ def available(self): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -82,6 +82,8 @@ def supported_features(self): @property def name(self): + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name @property diff --git a/custom_components/dirigera_platform/fan.py b/custom_components/dirigera_platform/fan.py index 4d6ce7b..4b0735a 100644 --- a/custom_components/dirigera_platform/fan.py +++ b/custom_components/dirigera_platform/fan.py @@ -173,7 +173,7 @@ def available(self): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -181,6 +181,8 @@ def device_info(self) -> DeviceInfo: @property def name(self) -> str: + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name @property diff --git a/custom_components/dirigera_platform/light.py b/custom_components/dirigera_platform/light.py index 707771f..a9d820b 100644 --- a/custom_components/dirigera_platform/light.py +++ b/custom_components/dirigera_platform/light.py @@ -49,7 +49,6 @@ async def async_setup_entry( async_add_entities(lights) logger.debug("LIGHT Complete async_setup_entry") - class ikea_bulb(LightEntity): _attr_has_entity_name = True @@ -111,7 +110,7 @@ def available(self): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -119,8 +118,10 @@ def device_info(self) -> DeviceInfo: @property def name(self): + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name - + @property def brightness(self): scaled = int((self._json_data.attributes.light_level / 100) * 255) @@ -211,4 +212,4 @@ def turn_off(self, **kwargs): except Exception as ex: logger.error("error encountered turning off : {}".format(self.name)) logger.error(ex) - raise HomeAssistantError(ex, DOMAIN, "hub_exception") + raise HomeAssistantError(ex, DOMAIN, "hub_exception") \ No newline at end of file diff --git a/custom_components/dirigera_platform/sensor.py b/custom_components/dirigera_platform/sensor.py index aed8c10..35406e1 100644 --- a/custom_components/dirigera_platform/sensor.py +++ b/custom_components/dirigera_platform/sensor.py @@ -127,7 +127,7 @@ def available(self): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -135,6 +135,8 @@ def device_info(self) -> DeviceInfo: @property def name(self) -> str: + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name @property @@ -289,7 +291,7 @@ def __init__(self, hub, json_data): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -309,6 +311,8 @@ def available(self): @property def name(self): + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name @property diff --git a/custom_components/dirigera_platform/switch.py b/custom_components/dirigera_platform/switch.py index 81828c2..12b6c4f 100644 --- a/custom_components/dirigera_platform/switch.py +++ b/custom_components/dirigera_platform/switch.py @@ -60,7 +60,7 @@ def available(self): def device_info(self) -> DeviceInfo: return DeviceInfo( identifiers={("dirigera_platform", self._json_data.id)}, - name=self._json_data.attributes.custom_name, + name=self.name, manufacturer=self._json_data.attributes.manufacturer, model=self._json_data.attributes.model, sw_version=self._json_data.attributes.firmware_version, @@ -68,6 +68,8 @@ def device_info(self) -> DeviceInfo: @property def name(self): + if self._json_data.attributes.custom_name is None or len(self._json_data.attributes.custom_name) == 0: + return self.unique_id return self._json_data.attributes.custom_name @property