hass-core/homeassistant/components/risco/entity.py
On Freund 635eda584d
Support for local push in Risco integration (#75874)
* Local config flow

* Local entities

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Address code review comments

* More type hints

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* More annotations

* Even more annonations

* New entity naming

* Move fixtures to conftest

* Improve state tests for local

* Remove mutable default arguments

* Remove assertions for lack of state

* Add missing file

* Switch setup to fixtures

* Use error fixtures in test_config_flow

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-08-24 13:09:54 +02:00

31 lines
926 B
Python

"""A risco entity base class."""
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import RiscoDataUpdateCoordinator
def binary_sensor_unique_id(risco, zone_id: int) -> str:
"""Return unique id for the binary sensor."""
return f"{risco.site_uuid}_zone_{zone_id}"
class RiscoEntity(CoordinatorEntity[RiscoDataUpdateCoordinator]):
"""Risco entity base class."""
def _get_data_from_coordinator(self):
raise NotImplementedError
def _refresh_from_coordinator(self):
self._get_data_from_coordinator()
self.async_write_ha_state()
async def async_added_to_hass(self):
"""When entity is added to hass."""
self.async_on_remove(
self.coordinator.async_add_listener(self._refresh_from_coordinator)
)
@property
def _risco(self):
"""Return the Risco API object."""
return self.coordinator.risco