From c674d1442b5c65edb19da1c25d1cb5642721a8ba Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 16:34:25 +0200 Subject: [PATCH 1/9] test with hvac mode --- custom_components/climate_group/climate.py | 24 ++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 0d2bf3d..2210a63 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -45,10 +45,10 @@ async def async_setup_platform(hass: HomeAssistantType, config: ConfigType, class ClimateGroup(ClimateDevice): - """Representation of a light group.""" + """Representation of a climate group.""" def __init__(self, name: str, entity_ids: List[str]) -> None: - """Initialize a light group.""" + """Initialize a climate group.""" self._name = name # type: str self._entity_ids = entity_ids # type: List[str] @@ -88,7 +88,7 @@ def name(self) -> str: @property def available(self) -> bool: - """Return whether the light group is available.""" + """Return whether the climate group is available.""" return self._available @property @@ -136,11 +136,11 @@ def temperature_unit(self): @property def should_poll(self) -> bool: - """No polling needed for a light group.""" + """No polling needed for a climate group.""" return False async def async_set_temperature(self, **kwargs): - """Forward the turn_on command to all lights in the light group.""" + """Forward the turn_on command to all climate in the climate group.""" data = {ATTR_ENTITY_ID: self._entity_ids} if ATTR_HVAC_MODE in kwargs: hvac_mode = kwargs.get(ATTR_HVAC_MODE) @@ -152,15 +152,23 @@ async def async_set_temperature(self, **kwargs): climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE, data, blocking=True) async def async_set_operation_mode(self, operation_mode): - """Forward the turn_on command to all lights in the light group.""" + """Forward the turn_on command to all climate in the climate group.""" data = {ATTR_ENTITY_ID: self._entity_ids, ATTR_HVAC_MODE: operation_mode} await self.hass.services.async_call( climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) + async def async_set_hvac_mode(self, operation_mode): + """Forward the turn_on command to all climate in the climate group.""" + data = {ATTR_ENTITY_ID: self._entity_ids, + ATTR_HVAC_MODE: hvac_mode} + + await self.hass.services.async_call( + climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) + async def async_update(self): - """Query all members and determine the light group state.""" + """Query all members and determine the climate group state.""" all_states = [self.hass.states.get(x) for x in self._entity_ids] states = list(filter(None, all_states)) self._target_temp = _reduce_attribute(states, 'temperature') @@ -185,7 +193,7 @@ async def async_update(self): # Merge supported features by emulating support for every feature # we find. self._supported_features |= support - # Bitwise-and the supported features with the GroupedLight's features + # Bitwise-and the supported features with the GroupedClimate's features # so that we don't break in the future when a new feature is added. self._supported_features &= SUPPORT_FLAGS From fd2cd30dddb23b74055861f65b944d91f026b969 Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 16:40:29 +0200 Subject: [PATCH 2/9] error in operation mode: hvac mode does not exist 2019-08-21 16:38:02 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.1545127728] async_set_hvac_mode() got an unexpected keyword argument 'hvac_mode' Traceback (most recent call last): File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 128, in handle_call_service connection.context(msg), File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py", line 1235, in async_call await asyncio.shield(self._execute_service(handler, service_call)) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py", line 1260, in _execute_service await handler.func(service_call) File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_component.py", line 210, in handle_service self._platforms.values(), func, call, service_name, required_features File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 334, in entity_service_call future.result() # pop exception if have File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 356, in _handle_service_platform_call await getattr(entity, func)(**data) TypeError: async_set_hvac_mode() got an unexpected keyword argument 'hvac_mode' --- custom_components/climate_group/climate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 2210a63..e9af0c5 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -162,7 +162,7 @@ async def async_set_operation_mode(self, operation_mode): async def async_set_hvac_mode(self, operation_mode): """Forward the turn_on command to all climate in the climate group.""" data = {ATTR_ENTITY_ID: self._entity_ids, - ATTR_HVAC_MODE: hvac_mode} + ATTR_HVAC_MODE: operation_mode} await self.hass.services.async_call( climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) From b9b3417eaf98430470e2d52f4955268e3135a38a Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 17:30:12 +0200 Subject: [PATCH 3/9] test --- custom_components/climate_group/climate.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index e9af0c5..7ff02db 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -107,8 +107,13 @@ def hvac_action(self): """ if self._mode == HVAC_MODE_OFF: return CURRENT_HVAC_OFF + else if self._mode == HVAC_MODE_HEAT: + return CURRENT_HVAC_HEAT + else if self._mode == CURRENT_HVAC_COOL: + return CURRENT_HVAC_COOL + else if self._mode == CURRENT_HVAC_AUTO: + return CURRENT_HVAC_AUTO return CURRENT_HVAC_HEAT - @property def hvac_modes(self): return self._mode_list @@ -158,14 +163,6 @@ async def async_set_operation_mode(self, operation_mode): await self.hass.services.async_call( climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) - - async def async_set_hvac_mode(self, operation_mode): - """Forward the turn_on command to all climate in the climate group.""" - data = {ATTR_ENTITY_ID: self._entity_ids, - ATTR_HVAC_MODE: operation_mode} - - await self.hass.services.async_call( - climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) async def async_update(self): """Query all members and determine the climate group state.""" From 70a303c043003b901ee0d70169c9dd9188553564 Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 17:36:36 +0200 Subject: [PATCH 4/9] test with HVAC_MODES --- custom_components/climate_group/climate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 7ff02db..8a110f9 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -20,7 +20,7 @@ from homeassistant.helpers.typing import HomeAssistantType, ConfigType from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA) from homeassistant.components.climate.const import ( - CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, ATTR_HVAC_MODE, HVAC_MODE_HEAT, PRESET_ECO, PRESET_COMFORT, + CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_AUTO,ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_AUTO, PRESET_ECO, PRESET_COMFORT, SUPPORT_TARGET_TEMPERATURE, HVAC_MODE_OFF, SUPPORT_PRESET_MODE) import homeassistant.helpers.config_validation as cv From 68fde04267e23c7891ab7348ea7a7c39a873004a Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 17:38:56 +0200 Subject: [PATCH 5/9] else if does not exist in python... --- custom_components/climate_group/climate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 8a110f9..4b954f0 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -107,11 +107,11 @@ def hvac_action(self): """ if self._mode == HVAC_MODE_OFF: return CURRENT_HVAC_OFF - else if self._mode == HVAC_MODE_HEAT: + elif self._mode == HVAC_MODE_HEAT: return CURRENT_HVAC_HEAT - else if self._mode == CURRENT_HVAC_COOL: + elif self._mode == CURRENT_HVAC_COOL: return CURRENT_HVAC_COOL - else if self._mode == CURRENT_HVAC_AUTO: + elif self._mode == CURRENT_HVAC_AUTO: return CURRENT_HVAC_AUTO return CURRENT_HVAC_HEAT @property From 5eee4cf30f83e149e4c919ff2ba9a15e2c2cbf80 Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 17:44:27 +0200 Subject: [PATCH 6/9] changed auto in dry, checked documentation. --- custom_components/climate_group/climate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 4b954f0..7bebd85 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -20,7 +20,7 @@ from homeassistant.helpers.typing import HomeAssistantType, ConfigType from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA) from homeassistant.components.climate.const import ( - CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_AUTO,ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_AUTO, PRESET_ECO, PRESET_COMFORT, + CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_DRY,ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, PRESET_ECO, PRESET_COMFORT, SUPPORT_TARGET_TEMPERATURE, HVAC_MODE_OFF, SUPPORT_PRESET_MODE) import homeassistant.helpers.config_validation as cv @@ -111,8 +111,8 @@ def hvac_action(self): return CURRENT_HVAC_HEAT elif self._mode == CURRENT_HVAC_COOL: return CURRENT_HVAC_COOL - elif self._mode == CURRENT_HVAC_AUTO: - return CURRENT_HVAC_AUTO + elif self._mode == CURRENT_HVAC_DRY: + return CURRENT_HVAC_DRY return CURRENT_HVAC_HEAT @property def hvac_modes(self): From e0bf68463b2563133c4748b034aff4f06784d182 Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 17:56:39 +0200 Subject: [PATCH 7/9] fixed set_hvac_mode and added idle_mode --- custom_components/climate_group/climate.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 7bebd85..70c7c5a 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -3,6 +3,9 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/climate.group/ + +For more details on climate component, please refer to the documentation at +https://developers.home-assistant.io/docs/en/entity_climate.html """ import logging import itertools @@ -20,7 +23,7 @@ from homeassistant.helpers.typing import HomeAssistantType, ConfigType from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA) from homeassistant.components.climate.const import ( - CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_DRY,ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, PRESET_ECO, PRESET_COMFORT, + CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_DRY, CURRENT_HVAC_IDLE, ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_IDLE, PRESET_ECO, PRESET_COMFORT, SUPPORT_TARGET_TEMPERATURE, HVAC_MODE_OFF, SUPPORT_PRESET_MODE) import homeassistant.helpers.config_validation as cv @@ -113,7 +116,9 @@ def hvac_action(self): return CURRENT_HVAC_COOL elif self._mode == CURRENT_HVAC_DRY: return CURRENT_HVAC_DRY - return CURRENT_HVAC_HEAT + elif self._mode == CURRENT_HVAC_IDLE + return CURRENT_HVAC_IDLE + @property def hvac_modes(self): return self._mode_list @@ -157,13 +162,21 @@ async def async_set_temperature(self, **kwargs): climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE, data, blocking=True) async def async_set_operation_mode(self, operation_mode): - """Forward the turn_on command to all climate in the climate group.""" + """Forward the turn_on command to all climate in the climate group. LEGACY CALL""" data = {ATTR_ENTITY_ID: self._entity_ids, ATTR_HVAC_MODE: operation_mode} await self.hass.services.async_call( climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) + async def async_set_hvac_mode(self, hvac_mode): + """Forward the turn_on command to all climate in the climate group.""" + data = {ATTR_ENTITY_ID: self._entity_ids, + ATTR_HVAC_MODE: hvac_mode} + + await self.hass.services.async_call( + climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) + async def async_update(self): """Query all members and determine the climate group state.""" all_states = [self.hass.states.get(x) for x in self._entity_ids] From db2620042478109674d440f8d6bb81297eab3e4d Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 18:08:25 +0200 Subject: [PATCH 8/9] Fixed typos and HVAC_MODES --- custom_components/climate_group/climate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 70c7c5a..5253b33 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -23,7 +23,7 @@ from homeassistant.helpers.typing import HomeAssistantType, ConfigType from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA) from homeassistant.components.climate.const import ( - CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_DRY, CURRENT_HVAC_IDLE, ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_IDLE, PRESET_ECO, PRESET_COMFORT, + CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_DRY, CURRENT_HVAC_IDLE, ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO, HVAC_MODE_FAN_ONLY, PRESET_ECO, PRESET_COMFORT, SUPPORT_TARGET_TEMPERATURE, HVAC_MODE_OFF, SUPPORT_PRESET_MODE) import homeassistant.helpers.config_validation as cv @@ -116,7 +116,7 @@ def hvac_action(self): return CURRENT_HVAC_COOL elif self._mode == CURRENT_HVAC_DRY: return CURRENT_HVAC_DRY - elif self._mode == CURRENT_HVAC_IDLE + elif self._mode == CURRENT_HVAC_IDLE: return CURRENT_HVAC_IDLE @property @@ -169,7 +169,7 @@ async def async_set_operation_mode(self, operation_mode): await self.hass.services.async_call( climate.DOMAIN, climate.SERVICE_SET_HVAC_MODE, data, blocking=True) - async def async_set_hvac_mode(self, hvac_mode): + async def async_set_hvac_mode(self, hvac_mode): """Forward the turn_on command to all climate in the climate group.""" data = {ATTR_ENTITY_ID: self._entity_ids, ATTR_HVAC_MODE: hvac_mode} From e94c73fe3745f9e616ffa985c1643c0b62d0a1f3 Mon Sep 17 00:00:00 2001 From: Matteo Franceschini Date: Wed, 21 Aug 2019 18:19:17 +0200 Subject: [PATCH 9/9] Minor style edits --- custom_components/climate_group/climate.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index 5253b33..ab4f1a2 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -23,8 +23,9 @@ from homeassistant.helpers.typing import HomeAssistantType, ConfigType from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA) from homeassistant.components.climate.const import ( - CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_DRY, CURRENT_HVAC_IDLE, ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO, HVAC_MODE_FAN_ONLY, PRESET_ECO, PRESET_COMFORT, - SUPPORT_TARGET_TEMPERATURE, HVAC_MODE_OFF, SUPPORT_PRESET_MODE) + CURRENT_HVAC_HEAT, CURRENT_HVAC_OFF, CURRENT_HVAC_COOL, CURRENT_HVAC_DRY, CURRENT_HVAC_IDLE, + ATTR_HVAC_MODE, HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO, + HVAC_MODE_FAN_ONLY, PRESET_ECO, PRESET_COMFORT, SUPPORT_TARGET_TEMPERATURE, HVAC_MODE_OFF, SUPPORT_PRESET_MODE) import homeassistant.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) @@ -162,7 +163,7 @@ async def async_set_temperature(self, **kwargs): climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE, data, blocking=True) async def async_set_operation_mode(self, operation_mode): - """Forward the turn_on command to all climate in the climate group. LEGACY CALL""" + """Forward the turn_on command to all climate in the climate group. LEGACY CALL. This will be used only if the hass version is old.""" data = {ATTR_ENTITY_ID: self._entity_ids, ATTR_HVAC_MODE: operation_mode}