Add wiffi integration (#30784)
* Add integration for wiffi devices wiffi devices are DIY board manufactured by stall.biz. Several devices are available, e.g. a weather station (weatherman), an indoor environmental sensor (wiffi-wz) and some more. This intgration has been developed using a weatherman device, but should also work for other devices from stall.biz. * Fix pylint warning * Use WIFFI / STALL WIFFI instead of wiffi to be consistent with stall.biz * Don't update disabled entities. * fix complains - move wiffi specific code to pypi - remove yaml configuration code * incorporate various suggestions from code review * fix remaining comments from Martin * fix comments * add tests for config flow * fix comments * add missing requirements for tests * fix pylint warnings * fix comments * fix comments remove debug log rename .translations to translations * rebase and adapt to latest dev branch * Update homeassistant/components/wiffi/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/wiffi/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * fix missing import Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
6464c94990
commit
ee96ff2846
16 changed files with 647 additions and 0 deletions
125
homeassistant/components/wiffi/sensor.py
Normal file
125
homeassistant/components/wiffi/sensor.py
Normal file
|
@ -0,0 +1,125 @@
|
|||
"""Sensor platform support for wiffi devices."""
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.const import DEGREE, PRESSURE_MBAR, TEMP_CELSIUS
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from . import WiffiEntity
|
||||
from .const import CREATE_ENTITY_SIGNAL
|
||||
from .wiffi_strings import (
|
||||
WIFFI_UOM_DEGREE,
|
||||
WIFFI_UOM_LUX,
|
||||
WIFFI_UOM_MILLI_BAR,
|
||||
WIFFI_UOM_PERCENT,
|
||||
WIFFI_UOM_TEMP_CELSIUS,
|
||||
)
|
||||
|
||||
# map to determine HA device class from wiffi's unit of measurement
|
||||
UOM_TO_DEVICE_CLASS_MAP = {
|
||||
WIFFI_UOM_TEMP_CELSIUS: DEVICE_CLASS_TEMPERATURE,
|
||||
WIFFI_UOM_PERCENT: DEVICE_CLASS_HUMIDITY,
|
||||
WIFFI_UOM_MILLI_BAR: DEVICE_CLASS_PRESSURE,
|
||||
WIFFI_UOM_LUX: DEVICE_CLASS_ILLUMINANCE,
|
||||
}
|
||||
|
||||
# map to convert wiffi unit of measurements to common HA uom's
|
||||
UOM_MAP = {
|
||||
WIFFI_UOM_DEGREE: DEGREE,
|
||||
WIFFI_UOM_TEMP_CELSIUS: TEMP_CELSIUS,
|
||||
WIFFI_UOM_MILLI_BAR: PRESSURE_MBAR,
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up platform for a new integration.
|
||||
|
||||
Called by the HA framework after async_forward_entry_setup has been called
|
||||
during initialization of a new integration (= wiffi).
|
||||
"""
|
||||
|
||||
@callback
|
||||
def _create_entity(device, metric):
|
||||
"""Create platform specific entities."""
|
||||
entities = []
|
||||
|
||||
if metric.is_number:
|
||||
entities.append(NumberEntity(device, metric))
|
||||
elif metric.is_string:
|
||||
entities.append(StringEntity(device, metric))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
async_dispatcher_connect(hass, CREATE_ENTITY_SIGNAL, _create_entity)
|
||||
|
||||
|
||||
class NumberEntity(WiffiEntity):
|
||||
"""Entity for wiffi metrics which have a number value."""
|
||||
|
||||
def __init__(self, device, metric):
|
||||
"""Initialize the entity."""
|
||||
super().__init__(device, metric)
|
||||
self._device_class = UOM_TO_DEVICE_CLASS_MAP.get(metric.unit_of_measurement)
|
||||
self._unit_of_measurement = UOM_MAP.get(
|
||||
metric.unit_of_measurement, metric.unit_of_measurement
|
||||
)
|
||||
self._value = metric.value
|
||||
self.reset_expiration_date()
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the automatically determined device class."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the value of the entity."""
|
||||
return self._value
|
||||
|
||||
@callback
|
||||
def _update_value_callback(self, device, metric):
|
||||
"""Update the value of the entity.
|
||||
|
||||
Called if a new message has been received from the wiffi device.
|
||||
"""
|
||||
self.reset_expiration_date()
|
||||
self._unit_of_measurement = UOM_MAP.get(
|
||||
metric.unit_of_measurement, metric.unit_of_measurement
|
||||
)
|
||||
self._value = metric.value
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
class StringEntity(WiffiEntity):
|
||||
"""Entity for wiffi metrics which have a string value."""
|
||||
|
||||
def __init__(self, device, metric):
|
||||
"""Initialize the entity."""
|
||||
super().__init__(device, metric)
|
||||
self._value = metric.value
|
||||
self.reset_expiration_date()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the value of the entity."""
|
||||
return self._value
|
||||
|
||||
@callback
|
||||
def _update_value_callback(self, device, metric):
|
||||
"""Update the value of the entity.
|
||||
|
||||
Called if a new message has been received from the wiffi device.
|
||||
"""
|
||||
self.reset_expiration_date()
|
||||
self._value = metric.value
|
||||
self.async_write_ha_state()
|
Loading…
Add table
Add a link
Reference in a new issue