This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -4,8 +4,13 @@ from typing import Any, Awaitable, Dict, Optional, List
from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import (
HVAC_MODE_OFF, HVAC_MODE_HEAT, PRESET_BOOST, PRESET_ACTIVITY,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_PRESET_MODE)
HVAC_MODE_OFF,
HVAC_MODE_HEAT,
PRESET_BOOST,
PRESET_ACTIVITY,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_PRESET_MODE,
)
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -14,34 +19,34 @@ from . import DOMAIN
_LOGGER = logging.getLogger(__name__)
ATTR_DURATION = 'duration'
ATTR_DURATION = "duration"
GH_ZONES = ['radiator']
GH_ZONES = ["radiator"]
# temperature is repeated here, as it gives access to high-precision temps
GH_STATE_ATTRS = ['mode', 'temperature', 'type', 'occupied', 'override']
GH_STATE_ATTRS = ["mode", "temperature", "type", "occupied", "override"]
# GeniusHub Zones support: Off, Timer, Override/Boost, Footprint & Linked modes
HA_HVAC_TO_GH = {
HVAC_MODE_OFF: 'off',
HVAC_MODE_HEAT: 'timer'
}
HA_HVAC_TO_GH = {HVAC_MODE_OFF: "off", HVAC_MODE_HEAT: "timer"}
GH_HVAC_TO_HA = {v: k for k, v in HA_HVAC_TO_GH.items()}
HA_PRESET_TO_GH = {
PRESET_ACTIVITY: 'footprint',
PRESET_BOOST: 'override'
}
HA_PRESET_TO_GH = {PRESET_ACTIVITY: "footprint", PRESET_BOOST: "override"}
GH_PRESET_TO_HA = {v: k for k, v in HA_PRESET_TO_GH.items()}
async def async_setup_platform(hass, hass_config, async_add_entities,
discovery_info=None):
async def async_setup_platform(
hass, hass_config, async_add_entities, discovery_info=None
):
"""Set up the Genius Hub climate entities."""
client = hass.data[DOMAIN]['client']
client = hass.data[DOMAIN]["client"]
async_add_entities([GeniusClimateZone(client, z)
for z in client.hub.zone_objs if z.type in GH_ZONES])
async_add_entities(
[
GeniusClimateZone(client, z)
for z in client.hub.zone_objs
if z.type in GH_ZONES
]
)
class GeniusClimateZone(ClimateDevice):
@ -52,7 +57,7 @@ class GeniusClimateZone(ClimateDevice):
self._client = client
self._zone = zone
if hasattr(self._zone, 'occupied'): # has a movement sensor
if hasattr(self._zone, "occupied"): # has a movement sensor
self._preset_modes = list(HA_PRESET_TO_GH)
else:
self._preset_modes = [PRESET_BOOST]
@ -74,7 +79,7 @@ class GeniusClimateZone(ClimateDevice):
def device_state_attributes(self) -> Dict[str, Any]:
"""Return the device state attributes."""
tmp = self._zone.__dict__.items()
return {'status': {k: v for k, v in tmp if k in GH_STATE_ATTRS}}
return {"status": {k: v for k, v in tmp if k in GH_STATE_ATTRS}}
@property
def should_poll(self) -> bool:
@ -138,8 +143,9 @@ class GeniusClimateZone(ClimateDevice):
async def async_set_temperature(self, **kwargs) -> Awaitable[None]:
"""Set a new target temperature for this zone."""
await self._zone.set_override(kwargs[ATTR_TEMPERATURE],
kwargs.get(ATTR_DURATION, 3600))
await self._zone.set_override(
kwargs[ATTR_TEMPERATURE], kwargs.get(ATTR_DURATION, 3600)
)
async def async_set_hvac_mode(self, hvac_mode: str) -> Awaitable[None]:
"""Set a new hvac mode."""
@ -147,4 +153,4 @@ class GeniusClimateZone(ClimateDevice):
async def async_set_preset_mode(self, preset_mode: str) -> Awaitable[None]:
"""Set a new preset mode."""
await self._zone.set_mode(HA_PRESET_TO_GH.get(preset_mode, 'timer'))
await self._zone.set_mode(HA_PRESET_TO_GH.get(preset_mode, "timer"))