Skip to content

Commit

Permalink
set entity_id
Browse files Browse the repository at this point in the history
  • Loading branch information
kingy444 committed Aug 30, 2024
1 parent 8359f63 commit 5d7d03a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions custom_components/electrolux_status/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/electrolux_status/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
18 changes: 13 additions & 5 deletions custom_components/electrolux_status/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/electrolux_status/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/electrolux_status/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions custom_components/electrolux_status/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 5 additions & 0 deletions custom_components/electrolux_status/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit 5d7d03a

Please sign in to comment.