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