1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-23 20:39:01 +00:00
Files
core/homeassistant/components/geniushub/climate.py
David Bonnes c78b3a4439 Tweak geniushub and bump client to v0.6.26 (#26640)
* use state attribute rather than type

* HA style tweaks

* small tweak

* bump client

* add more device_state_attributes

* bump client

* small tweak

* bump client for concurrent IO

* force snake_case, and refactor (consolidate) Devices/Zones

* force snake_case, and refactor (consolidate) Devices/Zones 2

* force snake_case, and refactor (consolidate) Devices/Zones 3

* refactor last_comms / wakeup_interval check

* movement sensor is dynamic, and tweaking

* tweak

* bump client to v0.6.20

* dummy

* dummy 2

* bump client to handle another edge case

* use entity_id fro zones

* small tweak

* bump client to 0.6.22

* add recursive snake_case converter

* fix regression

* fix regression 2

* fix regression 3

* remove Awaitables

* don't dynamically create function every scan_interval

* log kast_comms as localtime, delint dt_util

* add sensors fro v1 API

* tweak entity_id

* bump client

* bump client to v0.6.24

* bump client to v0.6.25

* explicit device attrs, dt as UTC

* add unique_id, remove entity_id

* Bump client to 0.6.26 - add Hub UID

* remove convert_dict()

* add mac_address (uid) for v1 API

* tweak var names

* add UID.upper() to avoid unwanted unique_id changes

* Update homeassistant/components/geniushub/__init__.py

Co-Authored-By: Martin Hjelmare <marhje52@kth.se>

* Update homeassistant/components/geniushub/__init__.py

Co-Authored-By: Martin Hjelmare <marhje52@kth.se>

* remove underscores

* refactor for broker

* ready now

* validate UID (MAC address)

* move uid to broker

* use existing constant

* pass client to broker
2019-10-02 17:27:13 +01:00

90 lines
2.9 KiB
Python

"""Support for Genius Hub climate devices."""
from typing import 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,
)
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
from . import DOMAIN, GeniusZone
# GeniusHub Zones support: Off, Timer, Override/Boost, Footprint & Linked modes
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"}
GH_PRESET_TO_HA = {v: k for k, v in HA_PRESET_TO_GH.items()}
GH_ZONES = ["radiator", "wet underfloor"]
async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
) -> None:
"""Set up the Genius Hub climate entities."""
if discovery_info is None:
return
broker = hass.data[DOMAIN]["broker"]
async_add_entities(
[
GeniusClimateZone(broker, z)
for z in broker.client.zone_objs
if z.data["type"] in GH_ZONES
]
)
class GeniusClimateZone(GeniusZone, ClimateDevice):
"""Representation of a Genius Hub climate device."""
def __init__(self, broker, zone) -> None:
"""Initialize the climate device."""
super().__init__(broker, zone)
self._max_temp = 28.0
self._min_temp = 4.0
self._supported_features = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
@property
def icon(self) -> str:
"""Return the icon to use in the frontend UI."""
return "mdi:radiator"
@property
def hvac_mode(self) -> str:
"""Return hvac operation ie. heat, cool mode."""
return GH_HVAC_TO_HA.get(self._zone.data["mode"], HVAC_MODE_HEAT)
@property
def hvac_modes(self) -> List[str]:
"""Return the list of available hvac operation modes."""
return list(HA_HVAC_TO_GH)
@property
def preset_mode(self) -> Optional[str]:
"""Return the current preset mode, e.g., home, away, temp."""
return GH_PRESET_TO_HA.get(self._zone.data["mode"])
@property
def preset_modes(self) -> Optional[List[str]]:
"""Return a list of available preset modes."""
if "occupied" in self._zone.data: # if has a movement sensor
return [PRESET_ACTIVITY, PRESET_BOOST]
return [PRESET_BOOST]
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set a new hvac mode."""
await self._zone.set_mode(HA_HVAC_TO_GH.get(hvac_mode))
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set a new preset mode."""
await self._zone.set_mode(HA_PRESET_TO_GH.get(preset_mode, "timer"))