* Add ecowitt integration * add tests * use total * use total * test coverage * Update homeassistant/components/ecowitt/__init__.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * Update homeassistant/components/ecowitt/binary_sensor.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * Update homeassistant/components/ecowitt/entity.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * Update homeassistant/components/ecowitt/diagnostics.py Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * add to async_on_unload * remove attr_name / unload callback * support unload platforms * using replace * address mapping * update type * mark final * Apply suggestions from code review Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Fix bracket * Fix another bracket * Address comment * Add strings * update tests * Update homeassistant/components/ecowitt/strings.json Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * update text * Update homeassistant/components/ecowitt/strings.json Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""The Ecowitt Weather Station Entity."""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
from aioecowitt import EcoWittSensor
|
|
|
|
from homeassistant.helpers.entity import DeviceInfo, Entity
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
class EcowittEntity(Entity):
|
|
"""Base class for Ecowitt Weather Station."""
|
|
|
|
_attr_has_entity_name = True
|
|
_attr_should_poll = False
|
|
|
|
def __init__(self, sensor: EcoWittSensor) -> None:
|
|
"""Construct the entity."""
|
|
self.ecowitt: EcoWittSensor = sensor
|
|
|
|
self._attr_unique_id = f"{sensor.station.key}-{sensor.key}"
|
|
self._attr_device_info = DeviceInfo(
|
|
identifiers={
|
|
(DOMAIN, sensor.station.key),
|
|
},
|
|
name=sensor.station.station,
|
|
model=sensor.station.model,
|
|
sw_version=sensor.station.version,
|
|
)
|
|
|
|
async def async_added_to_hass(self):
|
|
"""Install listener for updates later."""
|
|
|
|
def _update_state():
|
|
"""Update the state on callback."""
|
|
self.async_write_ha_state()
|
|
|
|
self.ecowitt.update_cb.append(_update_state)
|
|
self.async_on_remove(lambda: self.ecowitt.update_cb.remove(_update_state))
|
|
|
|
@property
|
|
def available(self) -> bool:
|
|
"""Return whether the state is based on actual reading from device."""
|
|
return (self.ecowitt.last_update_m + 5 * 60) > time.monotonic()
|