From 5d7d03af102dfe1f2ff67f17e44cfc60f8a5ef69 Mon Sep 17 00:00:00 2001 From: kingy444 Date: Fri, 30 Aug 2024 15:40:23 +1000 Subject: [PATCH] set entity_id --- .../electrolux_status/binary_sensor.py | 5 +++++ custom_components/electrolux_status/button.py | 5 +++++ custom_components/electrolux_status/entity.py | 18 +++++++++++++----- custom_components/electrolux_status/number.py | 5 +++++ custom_components/electrolux_status/select.py | 5 +++++ custom_components/electrolux_status/sensor.py | 5 +++++ custom_components/electrolux_status/switch.py | 5 +++++ 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/custom_components/electrolux_status/binary_sensor.py b/custom_components/electrolux_status/binary_sensor.py index f4ac176..6858003 100644 --- a/custom_components/electrolux_status/binary_sensor.py +++ b/custom_components/electrolux_status/binary_sensor.py @@ -39,6 +39,11 @@ async def async_setup_entry( class ElectroluxBinarySensor(ElectroluxEntity, BinarySensorEntity): """Electrolux Status binary_sensor class.""" + @property + def entity_domain(self): + """Enitity domain for the entry. Used for consistent entity_id.""" + return BINARY_SENSOR + @property def invert(self) -> bool: """Determine if the value returned for the entity needs to be reversed.""" diff --git a/custom_components/electrolux_status/button.py b/custom_components/electrolux_status/button.py index 5a36b95..038fb36 100644 --- a/custom_components/electrolux_status/button.py +++ b/custom_components/electrolux_status/button.py @@ -76,6 +76,11 @@ def __init__( ) self.val_to_send = val_to_send + @property + def entity_domain(self): + """Enitity domain for the entry. Used for consistent entity_id.""" + return BUTTON + @property def unique_id(self) -> str: """Return a unique ID to use for this entity.""" diff --git a/custom_components/electrolux_status/entity.py b/custom_components/electrolux_status/entity.py index eec77b7..e25e9a0 100644 --- a/custom_components/electrolux_status/entity.py +++ b/custom_components/electrolux_status/entity.py @@ -43,6 +43,8 @@ async def async_setup_entry( class ElectroluxEntity(CoordinatorEntity): """Class for Electorolux devices.""" + _attr_has_entity_name = True + appliance_status: ApplienceStatusResponse def __init__( @@ -80,6 +82,7 @@ def __init__( self.pnc_id = pnc_id self.unit = unit self.capability = capability + self.entity_id = f"{self.entity_domain}.{self.get_appliance.brand}_{self.get_appliance.name}_{self.entity_source}_{self.entity_attr}" if catalog_entry: self.entity_registry_enabled_default = ( catalog_entry.entity_registry_enabled_default @@ -90,6 +93,16 @@ def setup(self, data): """Initialiaze setup.""" self.data = data + @property + def entity_domain(self) -> str: + """Enitity domain for the entry.""" + return "sensor" + + @property + def unique_id(self) -> str: + """Return a unique ID to use for this entity.""" + return f"{self.config_entry.entry_id}-{self.entity_attr}-{self.entity_source or 'root'}-{self.pnc_id}" + # Disabled this as this removes the value from display : there is no readonly property for entities # @property # def available(self) -> bool: @@ -159,11 +172,6 @@ def get_appliance(self): """Return the appliance device.""" return self.coordinator.data["appliances"].get_appliance(self.pnc_id) - @property - def unique_id(self): - """Return a unique ID to use for this entity.""" - return f"{self.config_entry.entry_id}-{self.entity_attr}-{self.entity_source}-{self.pnc_id}" - @property def device_info(self): """Return identifiers of the device.""" diff --git a/custom_components/electrolux_status/number.py b/custom_components/electrolux_status/number.py index 2a93707..a5d2233 100644 --- a/custom_components/electrolux_status/number.py +++ b/custom_components/electrolux_status/number.py @@ -40,6 +40,11 @@ async def async_setup_entry( class ElectroluxNumber(ElectroluxEntity, NumberEntity): """Electrolux Status number class.""" + @property + def entity_domain(self): + """Enitity domain for the entry. Used for consistent entity_id.""" + return NUMBER + @property def native_value(self) -> float | None: """Return the value reported by the number.""" diff --git a/custom_components/electrolux_status/select.py b/custom_components/electrolux_status/select.py index 0727a72..c4dc7dd 100644 --- a/custom_components/electrolux_status/select.py +++ b/custom_components/electrolux_status/select.py @@ -84,6 +84,11 @@ def __init__( label = self.format_label(value) self.options_list[label] = value + @property + def entity_domain(self): + """Enitity domain for the entry. Used for consistent entity_id.""" + return SELECT + def format_label(self, value: str | None) -> str | None: """Convert input to label string value.""" if value is None: diff --git a/custom_components/electrolux_status/sensor.py b/custom_components/electrolux_status/sensor.py index d55e170..2eb2c25 100644 --- a/custom_components/electrolux_status/sensor.py +++ b/custom_components/electrolux_status/sensor.py @@ -40,6 +40,11 @@ async def async_setup_entry( class ElectroluxSensor(ElectroluxEntity, SensorEntity): """Electrolux Status Sensor class.""" + @property + def entity_domain(self): + """Enitity domain for the entry. Used for consistent entity_id.""" + return SENSOR + @property def suggested_display_precision(self) -> int | None: """Get the display precision.""" diff --git a/custom_components/electrolux_status/switch.py b/custom_components/electrolux_status/switch.py index ae6104f..c50aef4 100644 --- a/custom_components/electrolux_status/switch.py +++ b/custom_components/electrolux_status/switch.py @@ -40,6 +40,11 @@ async def async_setup_entry( class ElectroluxSwitch(ElectroluxEntity, SwitchEntity): """Electrolux Status switch class.""" + @property + def entity_domain(self): + """Enitity domain for the entry. Used for consistent entity_id.""" + return SWITCH + @property def is_on(self) -> bool: """Return true if the binary_sensor is on."""