Add disabled entities support to WLED (#31040)
This commit is contained in:
1 parent
96dba7b91f
commit
db76b91ffa
3 files changed
+73
-8
No files matched your search
@@ -118,10 +118,18 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
class WLEDEntity(Entity):
|
||||
"""Defines a base WLED entity."""
|
||||
|
||||
def __init__(self, entry_id: str, wled: WLED, name: str, icon: str) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
entry_id: str,
|
||||
wled: WLED,
|
||||
name: str,
|
||||
icon: str,
|
||||
enabled_default: bool = True,
|
||||
) -> None:
|
||||
"""Initialize the WLED entity."""
|
||||
self._attributes: Dict[str, Union[str, int, float]] = {}
|
||||
self._available = True
|
||||
self._enabled_default = enabled_default
|
||||
self._entry_id = entry_id
|
||||
self._icon = icon
|
||||
self._name = name
|
||||
@@ -143,6 +151,11 @@ class WLEDEntity(Entity):
|
||||
"""Return True if entity is available."""
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
return self._enabled_default
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""Return the polling requirement of the entity."""
|
||||
@@ -171,6 +184,9 @@ class WLEDEntity(Entity):
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update WLED entity."""
|
||||
if not self.enabled:
|
||||
return
|
||||
|
||||
if self.wled.device is None:
|
||||
self._available = False
|
||||
return
|
||||
|
||||
@@ -50,13 +50,14 @@ class WLEDSensor(WLEDDeviceEntity):
|
||||
icon: str,
|
||||
unit_of_measurement: str,
|
||||
key: str,
|
||||
enabled_default: bool = True,
|
||||
) -> None:
|
||||
"""Initialize WLED sensor."""
|
||||
self._state = None
|
||||
self._unit_of_measurement = unit_of_measurement
|
||||
self._key = key
|
||||
|
||||
super().__init__(entry_id, wled, name, icon)
|
||||
super().__init__(entry_id, wled, name, icon, enabled_default)
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
@@ -109,6 +110,7 @@ class WLEDUptimeSensor(WLEDSensor):
|
||||
"mdi:clock-outline",
|
||||
None,
|
||||
"uptime",
|
||||
enabled_default=False,
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -134,6 +136,7 @@ class WLEDFreeHeapSensor(WLEDSensor):
|
||||
"mdi:memory",
|
||||
DATA_BYTES,
|
||||
"free_heap",
|
||||
enabled_default=False,
|
||||
)
|
||||
|
||||
async def _wled_update(self) -> None:
|
||||
|
||||
Reference in new issue
Block a user