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,4 +1,6 @@
"""Support for an Intergas boiler via an InComfort/InTouch Lan2RF gateway.""" """Support for an Intergas heater via an InComfort/InTouch Lan2RF gateway."""
from typing import Any, Dict, Optional
from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -8,6 +10,9 @@ from . import DOMAIN
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up an InComfort/InTouch binary_sensor device.""" """Set up an InComfort/InTouch binary_sensor device."""
if discovery_info is None:
return
async_add_entities( async_add_entities(
[IncomfortFailed(hass.data[DOMAIN]["client"], hass.data[DOMAIN]["heater"])] [IncomfortFailed(hass.data[DOMAIN]["client"], hass.data[DOMAIN]["heater"])]
) )
@ -16,33 +21,40 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
class IncomfortFailed(BinarySensorDevice): class IncomfortFailed(BinarySensorDevice):
"""Representation of an InComfort Failed sensor.""" """Representation of an InComfort Failed sensor."""
def __init__(self, client, boiler): def __init__(self, client, heater) -> None:
"""Initialize the binary sensor.""" """Initialize the binary sensor."""
self._client = client self._unique_id = f"{heater.serial_no}_failed"
self._boiler = boiler
async def async_added_to_hass(self): self._client = client
self._heater = heater
async def async_added_to_hass(self) -> None:
"""Set up a listener when this entity is added to HA.""" """Set up a listener when this entity is added to HA."""
async_dispatcher_connect(self.hass, DOMAIN, self._refresh) async_dispatcher_connect(self.hass, DOMAIN, self._refresh)
@callback @callback
def _refresh(self): def _refresh(self) -> None:
self.async_schedule_update_ha_state(force_refresh=True) self.async_schedule_update_ha_state(force_refresh=True)
@property @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 the name of the sensor."""
return "Fault state" return "Fault state"
@property @property
def is_on(self): def is_on(self) -> bool:
"""Return the status of the sensor.""" """Return the status of the sensor."""
return self._boiler.status["is_failed"] return self._heater.status["is_failed"]
@property @property
def device_state_attributes(self): def device_state_attributes(self) -> Optional[Dict[str, Any]]:
"""Return the device state attributes.""" """Return the device state attributes."""
return {"fault_code": self._boiler.status["fault_code"]} return {"fault_code": self._heater.status["fault_code"]}
@property @property
def should_poll(self) -> bool: def should_poll(self) -> bool:

View file

@ -1,5 +1,5 @@
"""Support for an Intergas boiler via an InComfort/InTouch Lan2RF gateway.""" """Support for an Intergas boiler via an InComfort/InTouch Lan2RF gateway."""
from typing import Any, Dict, Optional, List from typing import Any, Dict, List, Optional
from homeassistant.components.climate import ClimateDevice from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import ( from homeassistant.components.climate.const import (
@ -13,21 +13,24 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import DOMAIN from . import DOMAIN
async def async_setup_platform( async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
hass, hass_config, async_add_entities, discovery_info=None
):
"""Set up an InComfort/InTouch climate device.""" """Set up an InComfort/InTouch climate device."""
if discovery_info is None:
return
client = hass.data[DOMAIN]["client"] client = hass.data[DOMAIN]["client"]
heater = hass.data[DOMAIN]["heater"] heater = hass.data[DOMAIN]["heater"]
async_add_entities([InComfortClimate(client, r) for r in heater.rooms]) async_add_entities([InComfortClimate(client, heater, r) for r in heater.rooms])
class InComfortClimate(ClimateDevice): class InComfortClimate(ClimateDevice):
"""Representation of an InComfort/InTouch climate device.""" """Representation of an InComfort/InTouch climate device."""
def __init__(self, client, room): def __init__(self, client, heater, room) -> None:
"""Initialize the climate device.""" """Initialize the climate device."""
self._unique_id = f"{heater.serial_no}_{room.room_no}"
self._client = client self._client = client
self._room = room self._room = room
self._name = f"Room {room.room_no}" self._name = f"Room {room.room_no}"
@ -37,7 +40,7 @@ class InComfortClimate(ClimateDevice):
async_dispatcher_connect(self.hass, DOMAIN, self._refresh) async_dispatcher_connect(self.hass, DOMAIN, self._refresh)
@callback @callback
def _refresh(self): def _refresh(self) -> None:
self.async_schedule_update_ha_state(force_refresh=True) self.async_schedule_update_ha_state(force_refresh=True)
@property @property
@ -45,6 +48,11 @@ class InComfortClimate(ClimateDevice):
"""Return False as this device should never be polled.""" """Return False as this device should never be polled."""
return False return False
@property
def unique_id(self) -> Optional[str]:
"""Return a unique ID."""
return self._unique_id
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the name of the climate device.""" """Return the name of the climate device."""
@ -78,7 +86,7 @@ class InComfortClimate(ClimateDevice):
@property @property
def target_temperature(self) -> Optional[float]: def target_temperature(self) -> Optional[float]:
"""Return the temperature we try to reach.""" """Return the temperature we try to reach."""
return self._room.override return self._room.setpoint
@property @property
def supported_features(self) -> int: def supported_features(self) -> int:

View file

@ -3,7 +3,7 @@
"name": "Intergas InComfort/Intouch Lan2RF gateway", "name": "Intergas InComfort/Intouch Lan2RF gateway",
"documentation": "https://www.home-assistant.io/components/incomfort", "documentation": "https://www.home-assistant.io/components/incomfort",
"requirements": [ "requirements": [
"incomfort-client==0.3.1" "incomfort-client==0.3.5"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [ "codeowners": [

View file

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

View file

@ -1,6 +1,7 @@
"""Support for an Intergas boiler via an InComfort/Intouch Lan2RF gateway.""" """Support for an Intergas boiler via an InComfort/Intouch Lan2RF gateway."""
import asyncio import asyncio
import logging import logging
from typing import Any, Dict, Optional
from aiohttp import ClientResponseError from aiohttp import ClientResponseError
from homeassistant.components.water_heater import WaterHeaterDevice from homeassistant.components.water_heater import WaterHeaterDevice
@ -11,60 +12,52 @@ from . import DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
HEATER_SUPPORT_FLAGS = 0 HEATER_ATTRS = ["display_code", "display_text", "is_burning"]
HEATER_MAX_TEMP = 80.0
HEATER_MIN_TEMP = 30.0
HEATER_NAME = "Boiler"
HEATER_ATTRS = [
"display_code",
"display_text",
"is_burning",
"rf_message_rssi",
"nodenr",
"rfstatus_cntr",
]
async def async_setup_platform( async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
hass, hass_config, async_add_entities, discovery_info=None
):
"""Set up an InComfort/Intouch water_heater device.""" """Set up an InComfort/Intouch water_heater device."""
if discovery_info is None:
return
client = hass.data[DOMAIN]["client"] client = hass.data[DOMAIN]["client"]
heater = hass.data[DOMAIN]["heater"] heater = hass.data[DOMAIN]["heater"]
async_add_entities([IncomfortWaterHeater(client, heater)], update_before_add=True) async_add_entities([IncomfortWaterHeater(client, heater)])
class IncomfortWaterHeater(WaterHeaterDevice): class IncomfortWaterHeater(WaterHeaterDevice):
"""Representation of an InComfort/Intouch water_heater device.""" """Representation of an InComfort/Intouch water_heater device."""
def __init__(self, client, heater): def __init__(self, client, heater) -> None:
"""Initialize the water_heater device.""" """Initialize the water_heater device."""
self._unique_id = f"{heater.serial_no}"
self._client = client self._client = client
self._heater = heater self._heater = heater
@property @property
def name(self): def unique_id(self) -> Optional[str]:
"""Return a unique ID."""
return self._unique_id
@property
def name(self) -> str:
"""Return the name of the water_heater device.""" """Return the name of the water_heater device."""
return HEATER_NAME return "Boiler"
@property @property
def icon(self): def icon(self) -> str:
"""Return the icon of the water_heater device.""" """Return the icon of the water_heater device."""
return "mdi:oil-temperature" return "mdi:thermometer-lines"
@property @property
def device_state_attributes(self): def device_state_attributes(self) -> Dict[str, Any]:
"""Return the device state attributes.""" """Return the device state attributes."""
state = { return {k: v for k, v in self._heater.status.items() if k in HEATER_ATTRS}
k: self._heater.status[k] for k in self._heater.status if k in HEATER_ATTRS
}
return state
@property @property
def current_temperature(self): def current_temperature(self) -> float:
"""Return the current temperature.""" """Return the current temperature."""
if self._heater.is_tapping: if self._heater.is_tapping:
return self._heater.tap_temp return self._heater.tap_temp
@ -73,34 +66,34 @@ class IncomfortWaterHeater(WaterHeaterDevice):
return max(self._heater.heater_temp, self._heater.tap_temp) return max(self._heater.heater_temp, self._heater.tap_temp)
@property @property
def min_temp(self): def min_temp(self) -> float:
"""Return max valid temperature that can be set.""" """Return max valid temperature that can be set."""
return HEATER_MIN_TEMP return 80.0
@property @property
def max_temp(self): def max_temp(self) -> float:
"""Return max valid temperature that can be set.""" """Return max valid temperature that can be set."""
return HEATER_MAX_TEMP return 30.0
@property @property
def temperature_unit(self): def temperature_unit(self) -> str:
"""Return the unit of measurement.""" """Return the unit of measurement."""
return TEMP_CELSIUS return TEMP_CELSIUS
@property @property
def supported_features(self): def supported_features(self) -> int:
"""Return the list of supported features.""" """Return the list of supported features."""
return HEATER_SUPPORT_FLAGS return 0
@property @property
def current_operation(self): def current_operation(self) -> str:
"""Return the current operation mode.""" """Return the current operation mode."""
if self._heater.is_failed: if self._heater.is_failed:
return f"Fault code: {self._heater.fault_code}" return f"Fault code: {self._heater.fault_code}"
return self._heater.display_text return self._heater.display_text
async def async_update(self): async def async_update(self) -> None:
"""Get the latest state data from the gateway.""" """Get the latest state data from the gateway."""
try: try:
await self._heater.update() await self._heater.update()
@ -108,4 +101,5 @@ class IncomfortWaterHeater(WaterHeaterDevice):
except (ClientResponseError, asyncio.TimeoutError) as err: except (ClientResponseError, asyncio.TimeoutError) as err:
_LOGGER.warning("Update failed, message is: %s", err) _LOGGER.warning("Update failed, message is: %s", err)
else:
async_dispatcher_send(self.hass, DOMAIN) async_dispatcher_send(self.hass, DOMAIN)

View file

@ -685,7 +685,7 @@ iglo==1.2.7
ihcsdk==2.3.0 ihcsdk==2.3.0
# homeassistant.components.incomfort # homeassistant.components.incomfort
incomfort-client==0.3.1 incomfort-client==0.3.5
# homeassistant.components.influxdb # homeassistant.components.influxdb
influxdb==5.2.3 influxdb==5.2.3