Skip to content

Commit 7b36fe1

Browse files
committed
implemented 'CoordinatorEntity' (update states max every second)
1 parent 4f4de86 commit 7b36fe1

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

custom_components/senec/__init__.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,12 +726,12 @@ async def entry_update_listener(hass: HomeAssistant, config_entry: ConfigEntry)
726726
class SenecEntity(CustomFriendlyNameEntity):
727727
"""Defines a base Senec entity."""
728728

729-
_attr_should_poll = False
730729
_attr_has_entity_name = True
731730

732731
def __init__(
733732
self, coordinator: SenecDataUpdateCoordinator, description: EntityDescription
734733
) -> None:
734+
super().__init__(coordinator, description)
735735
self.coordinator = coordinator
736736
self.entity_description = description
737737
self._name = coordinator._config_entry.title
@@ -809,15 +809,7 @@ def unique_id(self):
809809
async def async_added_to_hass(self):
810810
"""Connect to dispatcher listening for entity data notifications."""
811811
self.async_on_remove(self.coordinator.async_add_listener(self.async_write_ha_state))
812-
813-
async def async_update(self):
814-
"""Update entity."""
815-
await self.coordinator.async_request_refresh()
816-
817-
@property
818-
def should_poll(self) -> bool:
819-
"""Entities do not individually poll."""
820-
return False
812+
await super().async_added_to_hass()
821813

822814
def _friendly_name_internal(self) -> str | None:
823815
"""Return the friendly name.

custom_components/senec/entity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from awesomeversion import AwesomeVersion
44
from homeassistant.const import ATTR_FRIENDLY_NAME, __version__ as HA_VERSION
5-
from homeassistant.helpers.entity import Entity
5+
from homeassistant.helpers.update_coordinator import CoordinatorEntity
66

77
USE_NEW_FRIENDLY_NAME = AwesomeVersion(HA_VERSION) >= AwesomeVersion("2026.2.0")
88

99
_LOGGER = logging.getLogger(__name__)
1010
#_LOGGER.debug(f"HA Version: {HA_VERSION}, USE_NEW_FRIENDLY_NAME: {USE_NEW_FRIENDLY_NAME}")
1111

1212

13-
class CustomFriendlyNameEntity(Entity):
13+
class CustomFriendlyNameEntity(CoordinatorEntity):
1414

1515
def __init__(self, *args, **kwargs):
1616
"""Initialize and check if method exists."""

0 commit comments

Comments
 (0)