core/homeassistant/components/homematicip_cloud/climate.py

99 lines
3.1 KiB
Python
Raw Normal View History

"""Support for HomematicIP Cloud climate devices."""
import logging
2019-04-25 22:13:07 +00:00
from homematicip.aio.group import AsyncHeatingGroup
from homematicip.aio.home import AsyncHome
from homeassistant.components.climate import ClimateDevice
from homeassistant.components.climate.const import (
STATE_AUTO, STATE_MANUAL, SUPPORT_TARGET_TEMPERATURE)
2019-04-25 22:13:07 +00:00
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
2019-04-25 22:13:07 +00:00
from homeassistant.core import HomeAssistant
from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice
_LOGGER = logging.getLogger(__name__)
HA_STATE_TO_HMIP = {
STATE_AUTO: 'AUTOMATIC',
STATE_MANUAL: 'MANUAL',
}
HMIP_STATE_TO_HA = {value: key for key, value in HA_STATE_TO_HMIP.items()}
2018-08-21 19:25:16 +00:00
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
2018-08-21 19:25:16 +00:00
"""Set up the HomematicIP Cloud climate devices."""
Add HomematicIP Cloud Config Flow and Entries loading (#14861) * Add HomematicIP Cloud to config flow * Inititial trial for config_flow * Integrations text files * Load and write config_flow and init homematicip_cloud * Split into dedicated files * Ceanup of text messages * Working config_flow * Move imports inside a function * Enable laoding even no accesspoints are defined * Revert unnecassary changes in CONFIG_SCHEMA * Better error handling * fix flask8 * Migration to async for token generation * A few fixes * Simplify config_flow * Bump version to 9.6 with renamed package * Requirements file * First fixes after review * Implement async_step_import * Cleanup for Config Flow * First tests for homematicip_cloud setup * Remove config_flow tests * Really remove all things * Fix comment * Update picture * Add support for async_setup_entry to switch and climate platform * Update path of the config_flow picture * Refactoring for better tesability * Further tests implemented * Move 3th party lib inside function * Fix lint * Update requirments_test_all.txt file * UPdate of requirments_test_all.txt did not work * Furder cleanup in websocket connection * Remove a test for the hap * Revert "Remove a test for the hap" This reverts commit 968d58cba108e0f371022c7ab540374aa2ab13f4. * First tests implemented for config_flow * Fix lint * Rework of client registration process * Implemented tests for config_flow 100% coverage * Cleanup * Cleanup comments and code * Try to fix import problem * Add homematicip to the test env requirements
2018-07-06 21:05:34 +00:00
pass
2019-04-25 22:13:07 +00:00
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry,
async_add_entities) -> None:
Add HomematicIP Cloud Config Flow and Entries loading (#14861) * Add HomematicIP Cloud to config flow * Inititial trial for config_flow * Integrations text files * Load and write config_flow and init homematicip_cloud * Split into dedicated files * Ceanup of text messages * Working config_flow * Move imports inside a function * Enable laoding even no accesspoints are defined * Revert unnecassary changes in CONFIG_SCHEMA * Better error handling * fix flask8 * Migration to async for token generation * A few fixes * Simplify config_flow * Bump version to 9.6 with renamed package * Requirements file * First fixes after review * Implement async_step_import * Cleanup for Config Flow * First tests for homematicip_cloud setup * Remove config_flow tests * Really remove all things * Fix comment * Update picture * Add support for async_setup_entry to switch and climate platform * Update path of the config_flow picture * Refactoring for better tesability * Further tests implemented * Move 3th party lib inside function * Fix lint * Update requirments_test_all.txt file * UPdate of requirments_test_all.txt did not work * Furder cleanup in websocket connection * Remove a test for the hap * Revert "Remove a test for the hap" This reverts commit 968d58cba108e0f371022c7ab540374aa2ab13f4. * First tests implemented for config_flow * Fix lint * Rework of client registration process * Implemented tests for config_flow 100% coverage * Cleanup * Cleanup comments and code * Try to fix import problem * Add homematicip to the test env requirements
2018-07-06 21:05:34 +00:00
"""Set up the HomematicIP climate from a config entry."""
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
devices = []
for device in home.groups:
2019-04-25 22:13:07 +00:00
if isinstance(device, AsyncHeatingGroup):
devices.append(HomematicipHeatingGroup(home, device))
if devices:
async_add_entities(devices)
class HomematicipHeatingGroup(HomematicipGenericDevice, ClimateDevice):
2018-08-21 19:25:16 +00:00
"""Representation of a HomematicIP heating group."""
2019-04-25 22:13:07 +00:00
def __init__(self, home: AsyncHome, device) -> None:
"""Initialize heating group."""
device.modelType = 'Group-Heating'
super().__init__(home, device)
@property
2019-04-25 22:13:07 +00:00
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
@property
2019-04-25 22:13:07 +00:00
def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE
@property
2019-04-25 22:13:07 +00:00
def target_temperature(self) -> float:
"""Return the temperature we try to reach."""
return self._device.setPointTemperature
@property
2019-04-25 22:13:07 +00:00
def current_temperature(self) -> float:
"""Return the current temperature."""
return self._device.actualTemperature
@property
2019-04-25 22:13:07 +00:00
def current_humidity(self) -> int:
"""Return the current humidity."""
return self._device.humidity
@property
2019-04-25 22:13:07 +00:00
def current_operation(self) -> str:
"""Return current operation ie. automatic or manual."""
return HMIP_STATE_TO_HA.get(self._device.controlMode)
@property
2019-04-25 22:13:07 +00:00
def min_temp(self) -> float:
"""Return the minimum temperature."""
return self._device.minTemperature
@property
2019-04-25 22:13:07 +00:00
def max_temp(self) -> float:
"""Return the maximum temperature."""
return self._device.maxTemperature
async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
await self._device.set_point_temperature(temperature)