Allow preset boost for Homematic IP Cloud power switches (#28713)

* Allow preset boost for Homematic IP Cloud  power switches

* Sort Imports

* Add test

* align test data
This commit is contained in:
SukramJ 2019-11-12 11:32:32 +01:00 committed by Martin Hjelmare
parent 4f11eec1a1
commit e8348221d4
3 changed files with 46 additions and 8 deletions

View File

@ -5,6 +5,7 @@ from typing import Awaitable
from homematicip.aio.device import AsyncHeatingThermostat, AsyncHeatingThermostatCompact
from homematicip.aio.group import AsyncHeatingGroup
from homematicip.base.enums import AbsenceType
from homematicip.device import Switch
from homematicip.functionalHomes import IndoorClimateHome
from homeassistant.components.climate import ClimateDevice
@ -116,7 +117,7 @@ class HomematicipHeatingGroup(HomematicipGenericDevice, ClimateDevice):
@property
def hvac_mode(self) -> str:
"""Return hvac operation ie."""
if self._disabled_by_cooling_mode:
if self._disabled_by_cooling_mode and not self._has_switch:
return HVAC_MODE_OFF
if self._device.boostMode:
return HVAC_MODE_HEAT
@ -128,7 +129,7 @@ class HomematicipHeatingGroup(HomematicipGenericDevice, ClimateDevice):
@property
def hvac_modes(self):
"""Return the list of available hvac operation modes."""
if self._disabled_by_cooling_mode:
if self._disabled_by_cooling_mode and not self._has_switch:
return [HVAC_MODE_OFF]
return (
@ -168,7 +169,9 @@ class HomematicipHeatingGroup(HomematicipGenericDevice, ClimateDevice):
profile_names = self._device_profile_names
presets = []
if self._heat_mode_enabled and self._has_radiator_thermostat:
if (
self._heat_mode_enabled and self._has_radiator_thermostat
) or self._has_switch:
if not profile_names:
presets.append(PRESET_NONE)
presets.append(PRESET_BOOST)
@ -290,6 +293,15 @@ class HomematicipHeatingGroup(HomematicipGenericDevice, ClimateDevice):
return HEATING_PROFILES if self._heat_mode_enabled else COOLING_PROFILES
@property
def _has_switch(self) -> bool:
"""Return, if a switch is in the hmip heating group."""
for device in self._device.devices:
if isinstance(device, Switch):
return True
return False
@property
def _has_radiator_thermostat(self) -> bool:
"""Return, if a radiator thermostat is in the hmip heating group."""

View File

@ -333,6 +333,26 @@ async def test_hmip_heating_group_cool(hass, default_mock_hap):
assert hmip_device.mock_calls[-1][1] == (4,)
async def test_hmip_heating_group_heat_with_switch(hass, default_mock_hap):
"""Test HomematicipHeatingGroup."""
entity_id = "climate.schlafzimmer"
entity_name = "Schlafzimmer"
device_model = None
ha_state, hmip_device = get_and_check_entity_basics(
hass, default_mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == HVAC_MODE_AUTO
assert ha_state.attributes["current_temperature"] == 24.7
assert ha_state.attributes["min_temp"] == 5.0
assert ha_state.attributes["max_temp"] == 30.0
assert ha_state.attributes["temperature"] == 5.0
assert ha_state.attributes["current_humidity"] == 43
assert ha_state.attributes[ATTR_PRESET_MODE] == "STD"
assert ha_state.attributes[ATTR_PRESET_MODES] == [PRESET_BOOST, "STD", "P2"]
async def test_hmip_climate_services(hass, mock_hap_with_service):
"""Test HomematicipHeatingGroup."""

View File

@ -5,6 +5,12 @@
"id": "00000000-0000-0000-0000-000000000000",
"label": "TEST-Client",
"clientType": "APP"
},
"AA000000-0000-0000-0000-000000000000": {
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "AA000000-0000-0000-0000-000000000000",
"label": "REMOVE_ME",
"clientType": "APP"
}
},
"devices": {
@ -1485,7 +1491,7 @@
"modelType": "HmIP-SMI",
"oem": "eQ-3",
"permanentlyReachable": true,
"serializedGlobalTradeItemNumber": "3014F7110000000000000011",
"serializedGlobalTradeItemNumber": "3014F711000000000000BB11",
"type": "MOTION_DETECTOR_INDOOR",
"updateState": "UP_TO_DATE"
},
@ -2202,7 +2208,7 @@
}
},
"homeId": "00000000-0000-0000-0000-000000000001",
"id": "3014F7110000000000000011",
"id": "3014F7110000000000000109",
"label": "Ausschalter Terrasse Bewegungsmelder",
"lastStatusUpdate": 1570366291250,
"liveUpdateState": "LIVE_UPDATE_NOT_SUPPORTED",
@ -4075,7 +4081,7 @@
},
{
"channelIndex": 1,
"deviceId": "3014F7110000000000000011"
"deviceId": "3014F7110000000000000008"
}
],
"controlMode": "AUTOMATIC",
@ -4109,7 +4115,7 @@
"enabled": true,
"groupId": "00000000-0000-0000-0000-000000000012",
"index": "PROFILE_1",
"name": "",
"name": "STD",
"profileId": "00000000-0000-0000-0000-000000000023",
"visible": true
},
@ -4117,7 +4123,7 @@
"enabled": true,
"groupId": "00000000-0000-0000-0000-000000000012",
"index": "PROFILE_2",
"name": "",
"name": "P2",
"profileId": "00000000-0000-0000-0000-000000000024",
"visible": true
},