[ci skip] home assistant integration
This commit is contained in:
29
custom_components/victron_mk2_mqtt/entity.py
Normal file
29
custom_components/victron_mk2_mqtt/entity.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user