30 lines
810 B
Python
30 lines
810 B
Python
"""Shared entity base for Victron MK2 MQTT."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
from .coordinator import VictronMqttBridge
|
|
|
|
|
|
class VictronMqttEntity(Entity):
|
|
"""Base entity bound to shared MQTT bridge."""
|
|
|
|
_attr_should_poll = False
|
|
_attr_has_entity_name = True
|
|
|
|
def __init__(self, bridge: VictronMqttBridge) -> None:
|
|
self.bridge = bridge
|
|
|
|
@property
|
|
def device_info(self):
|
|
"""Return the shared device info."""
|
|
return self.bridge.device_info
|
|
|
|
async def async_added_to_hass(self) -> None:
|
|
"""Register for coordinator updates."""
|
|
self.async_on_remove(self.bridge.async_add_listener(self._handle_bridge_update))
|
|
|
|
def _handle_bridge_update(self) -> None:
|
|
self.async_write_ha_state()
|