Fix incomfort and Bump client to 0.3.5 (#26802)

* remove superfluous device state attributes
* fix water_heater icon
* add type hints
* fix issue #26760
* bump client to v0.3.5
* add unique_id
This commit is contained in:
David Bonnes 2019-09-30 09:31:35 +01:00 committed by GitHub
parent c527e0f164
commit fa92d0e6d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 125 additions and 98 deletions

View file

@ -1,31 +1,43 @@
"""Support for an Intergas boiler via an InComfort/InTouch Lan2RF gateway."""
from homeassistant.const import PRESSURE_BAR, TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE
"""Support for an Intergas heater via an InComfort/InTouch Lan2RF gateway."""
from typing import Any, Dict, Optional
from homeassistant.const import (
PRESSURE_BAR,
TEMP_CELSIUS,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
)
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
from . import DOMAIN
INTOUCH_HEATER_TEMP = "CV Temp"
INTOUCH_PRESSURE = "CV Pressure"
INTOUCH_TAP_TEMP = "Tap Temp"
INCOMFORT_HEATER_TEMP = "CV Temp"
INCOMFORT_PRESSURE = "CV Pressure"
INCOMFORT_TAP_TEMP = "Tap Temp"
INTOUCH_MAP_ATTRS = {
INTOUCH_HEATER_TEMP: ["heater_temp", "is_pumping"],
INTOUCH_TAP_TEMP: ["tap_temp", "is_tapping"],
INCOMFORT_MAP_ATTRS = {
INCOMFORT_HEATER_TEMP: ["heater_temp", "is_pumping"],
INCOMFORT_PRESSURE: ["pressure", None],
INCOMFORT_TAP_TEMP: ["tap_temp", "is_tapping"],
}
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up an InComfort/InTouch sensor device."""
if discovery_info is None:
return
client = hass.data[DOMAIN]["client"]
heater = hass.data[DOMAIN]["heater"]
async_add_entities(
[
IncomfortPressure(client, heater, INTOUCH_PRESSURE),
IncomfortTemperature(client, heater, INTOUCH_HEATER_TEMP),
IncomfortTemperature(client, heater, INTOUCH_TAP_TEMP),
IncomfortPressure(client, heater, INCOMFORT_PRESSURE),
IncomfortTemperature(client, heater, INCOMFORT_HEATER_TEMP),
IncomfortTemperature(client, heater, INCOMFORT_TAP_TEMP),
]
)
@ -33,35 +45,47 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
class IncomfortSensor(Entity):
"""Representation of an InComfort/InTouch sensor device."""
def __init__(self, client, boiler):
def __init__(self, client, heater, name) -> None:
"""Initialize the sensor."""
self._client = client
self._boiler = boiler
self._heater = heater
self._name = None
self._unique_id = f"{heater.serial_no}_{slugify(name)}"
self._name = name
self._device_class = None
self._unit_of_measurement = None
async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Set up a listener when this entity is added to HA."""
async_dispatcher_connect(self.hass, DOMAIN, self._refresh)
@callback
def _refresh(self):
def _refresh(self) -> None:
self.async_schedule_update_ha_state(force_refresh=True)
@property
def name(self):
def unique_id(self) -> Optional[str]:
"""Return a unique ID."""
return self._unique_id
@property
def name(self) -> Optional[str]:
"""Return the name of the sensor."""
return self._name
@property
def device_class(self):
def state(self) -> Optional[str]:
"""Return the state of the sensor."""
return self._heater.status[INCOMFORT_MAP_ATTRS[self._name][0]]
@property
def device_class(self) -> Optional[str]:
"""Return the device class of the sensor."""
return self._device_class
@property
def unit_of_measurement(self):
def unit_of_measurement(self) -> Optional[str]:
"""Return the unit of measurement of the sensor."""
return self._unit_of_measurement
@ -74,37 +98,26 @@ class IncomfortSensor(Entity):
class IncomfortPressure(IncomfortSensor):
"""Representation of an InTouch CV Pressure sensor."""
def __init__(self, client, boiler, name):
def __init__(self, client, heater, name) -> None:
"""Initialize the sensor."""
super().__init__(client, boiler)
super().__init__(client, heater, name)
self._name = name
self._device_class = DEVICE_CLASS_PRESSURE
self._unit_of_measurement = PRESSURE_BAR
@property
def state(self):
"""Return the state/value of the sensor."""
return self._boiler.status["pressure"]
class IncomfortTemperature(IncomfortSensor):
"""Representation of an InTouch Temperature sensor."""
def __init__(self, client, boiler, name):
def __init__(self, client, heater, name) -> None:
"""Initialize the signal strength sensor."""
super().__init__(client, boiler)
super().__init__(client, heater, name)
self._name = name
self._device_class = DEVICE_CLASS_TEMPERATURE
self._unit_of_measurement = TEMP_CELSIUS
@property
def state(self):
"""Return the state of the sensor."""
return self._boiler.status[INTOUCH_MAP_ATTRS[self._name][0]]
@property
def device_state_attributes(self):
def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return the device state attributes."""
key = INTOUCH_MAP_ATTRS[self._name][1]
return {key: self._boiler.status[key]}
key = INCOMFORT_MAP_ATTRS[self._name][1]
return {key: self._heater.status[key]}