Skip to content

Commit

Permalink
Takes care of zero len custom_name
Browse files Browse the repository at this point in the history
  • Loading branch information
c503ghosh committed Mar 30, 2024
1 parent d3140ee commit 3f3727a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
8 changes: 6 additions & 2 deletions custom_components/dirigera_platform/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ 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,
)

@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
Expand All @@ -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,
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion custom_components/dirigera_platform/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion custom_components/dirigera_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,16 @@ 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,
)

@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
Expand Down
9 changes: 5 additions & 4 deletions custom_components/dirigera_platform/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -111,16 +110,18 @@ 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,
)

@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)
Expand Down Expand Up @@ -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")
8 changes: 6 additions & 2 deletions custom_components/dirigera_platform/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ 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,
)

@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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion custom_components/dirigera_platform/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ 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,
)

@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
Expand Down

0 comments on commit 3f3727a

Please sign in to comment.