Add water_heater to geniushub, bump client library (#23384)

* add water_heater

* add geniushub/water_heater.py

* de-lint

* de-lint 2

* remove temperature from device state attribs

* update to latest client library

* add me as CODEOWNER

* bump client

* bump client

* delint/refactor

* Update homeassistant/components/geniushub/water_heater.py

Co-Authored-By: zxdavb <david@bonnes.me>
pull/23740/head
David Bonnes 2019-05-07 16:37:47 +01:00 committed by Martin Hjelmare
parent f386088def
commit 6611d585e6
6 changed files with 158 additions and 11 deletions

View File

@ -85,6 +85,7 @@ homeassistant/components/foursquare/* @robbiet480
homeassistant/components/freebox/* @snoof85
homeassistant/components/frontend/* @home-assistant/core
homeassistant/components/gearbest/* @HerrHofrat
homeassistant/components/geniushub/* @zxdavb
homeassistant/components/gitter/* @fabaff
homeassistant/components/glances/* @fabaff
homeassistant/components/gntp/* @robbiet480

View File

@ -57,4 +57,7 @@ async def async_setup(hass, hass_config):
hass.async_create_task(async_load_platform(
hass, 'climate', DOMAIN, {}, hass_config))
hass.async_create_task(async_load_platform(
hass, 'water_heater', DOMAIN, {}, hass_config))
return True

View File

@ -1,4 +1,4 @@
"""Supports Genius hub to provide climate controls."""
"""Support for Genius Hub climate devices."""
import asyncio
import logging
@ -13,6 +13,8 @@ from . import DOMAIN
_LOGGER = logging.getLogger(__name__)
GH_CLIMATE_DEVICES = ['radiator']
GENIUSHUB_SUPPORT_FLAGS = \
SUPPORT_TARGET_TEMPERATURE | \
SUPPORT_ON_OFF | \
@ -21,7 +23,7 @@ GENIUSHUB_SUPPORT_FLAGS = \
GENIUSHUB_MAX_TEMP = 28.0
GENIUSHUB_MIN_TEMP = 4.0
# Genius supports only Off, Override/Boost, Footprint & Timer modes
# Genius Hub Zones support only Off, Override/Boost, Footprint & Timer modes
HA_OPMODE_TO_GH = {
STATE_AUTO: 'timer',
STATE_ECO: 'footprint',
@ -38,20 +40,20 @@ GH_STATE_TO_HA = {
'linked': None,
'other': None,
} # intentionally missing 'off': None
# temperature is repeated here, as it gives access to high-precision temps
GH_DEVICE_STATE_ATTRS = ['temperature', 'type', 'occupied', 'override']
async def async_setup_platform(hass, hass_config, async_add_entities,
discovery_info=None):
"""Set up the Genius hub climate devices."""
"""Set up the Genius Hub climate entities."""
client = hass.data[DOMAIN]['client']
zones = []
for zone in client.hub.zone_objs:
if hasattr(zone, 'temperature'):
zones.append(GeniusClimate(client, zone))
entities = [GeniusClimate(client, z)
for z in client.hub.zone_objs if z.type in GH_CLIMATE_DEVICES]
async_add_entities(zones)
async_add_entities(entities)
class GeniusClimate(ClimateDevice):

View File

@ -3,8 +3,8 @@
"name": "Genius Hub",
"documentation": "https://www.home-assistant.io/components/geniushub",
"requirements": [
"geniushub-client==0.4.5"
"geniushub-client==0.4.6"
],
"dependencies": [],
"codeowners": []
"codeowners": ["@zxdavb"]
}

View File

@ -0,0 +1,141 @@
"""Support for Genius Hub water_heater devices."""
import asyncio
import logging
from homeassistant.components.water_heater import (
WaterHeaterDevice,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE)
from homeassistant.const import (
ATTR_TEMPERATURE, STATE_OFF, TEMP_CELSIUS)
from . import DOMAIN
STATE_AUTO = 'auto'
STATE_MANUAL = 'manual'
_LOGGER = logging.getLogger(__name__)
GH_WATER_HEATERS = ['hot water temperature']
GENIUSHUB_SUPPORT_FLAGS = \
SUPPORT_TARGET_TEMPERATURE | \
SUPPORT_OPERATION_MODE
# HA does not have SUPPORT_ON_OFF for water_heater
GENIUSHUB_MAX_TEMP = 80.0
GENIUSHUB_MIN_TEMP = 30.0
# Genius Hub HW supports only Off, Override/Boost & Timer modes
HA_OPMODE_TO_GH = {
STATE_OFF: 'off',
STATE_AUTO: 'timer',
STATE_MANUAL: 'override',
}
GH_OPMODE_OFF = 'off'
GH_STATE_TO_HA = {
'off': STATE_OFF,
'timer': STATE_AUTO,
'footprint': None,
'away': None,
'override': STATE_MANUAL,
'early': None,
'test': None,
'linked': None,
'other': None,
}
GH_DEVICE_STATE_ATTRS = ['type', 'override']
async def async_setup_platform(hass, hass_config, async_add_entities,
discovery_info=None):
"""Set up the Genius Hub water_heater entities."""
client = hass.data[DOMAIN]['client']
entities = [GeniusWaterHeater(client, z)
for z in client.hub.zone_objs if z.type in GH_WATER_HEATERS]
async_add_entities(entities)
class GeniusWaterHeater(WaterHeaterDevice):
"""Representation of a Genius Hub water_heater device."""
def __init__(self, client, boiler):
"""Initialize the water_heater device."""
self._client = client
self._boiler = boiler
self._id = boiler.id
self._name = boiler.name
self._operation_list = list(HA_OPMODE_TO_GH)
@property
def name(self):
"""Return the name of the water_heater device."""
return self._boiler.name
@property
def device_state_attributes(self):
"""Return the device state attributes."""
tmp = self._boiler.__dict__.items()
state = {k: v for k, v in tmp if k in GH_DEVICE_STATE_ATTRS}
return {'status': state}
@property
def current_temperature(self):
"""Return the current temperature."""
return self._boiler.temperature
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return self._boiler.setpoint
@property
def min_temp(self):
"""Return max valid temperature that can be set."""
return GENIUSHUB_MIN_TEMP
@property
def max_temp(self):
"""Return max valid temperature that can be set."""
return GENIUSHUB_MAX_TEMP
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property
def supported_features(self):
"""Return the list of supported features."""
return GENIUSHUB_SUPPORT_FLAGS
@property
def operation_list(self):
"""Return the list of available operation modes."""
return self._operation_list
@property
def current_operation(self):
"""Return the current operation mode."""
return GH_STATE_TO_HA.get(self._boiler.mode)
async def async_set_operation_mode(self, operation_mode):
"""Set a new operation mode for this boiler."""
await self._boiler.set_mode(HA_OPMODE_TO_GH.get(operation_mode))
async def async_set_temperature(self, **kwargs):
"""Set a new target temperature for this boiler."""
temperature = kwargs[ATTR_TEMPERATURE]
await self._boiler.set_override(temperature, 3600) # 1 hour
async def async_update(self):
"""Get the latest data from the hub."""
try:
await self._boiler.update()
except (AssertionError, asyncio.TimeoutError) as err:
_LOGGER.warning("Update for %s failed, message: %s",
self._id, err)

View File

@ -474,7 +474,7 @@ gearbest_parser==1.0.7
geizhals==0.0.9
# homeassistant.components.geniushub
geniushub-client==0.4.5
geniushub-client==0.4.6
# homeassistant.components.geo_json_events
# homeassistant.components.nsw_rural_fire_service_feed