mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Address late review of deconz climate (#70148)
* Fix late comment * Avoid unnecessary properties * Add clip sensor test to increase coverage of climate * Fix review_comment
This commit is contained in:
parent
a2337f4a43
commit
f0b1d35562
@ -62,7 +62,6 @@ FAN_MODE_TO_DECONZ = {
|
|||||||
FAN_ON: THERMOSTAT_FAN_MODE_ON,
|
FAN_ON: THERMOSTAT_FAN_MODE_ON,
|
||||||
FAN_OFF: THERMOSTAT_FAN_MODE_OFF,
|
FAN_OFF: THERMOSTAT_FAN_MODE_OFF,
|
||||||
}
|
}
|
||||||
|
|
||||||
DECONZ_TO_FAN_MODE = {value: key for key, value in FAN_MODE_TO_DECONZ.items()}
|
DECONZ_TO_FAN_MODE = {value: key for key, value in FAN_MODE_TO_DECONZ.items()}
|
||||||
|
|
||||||
HVAC_MODE_TO_DECONZ: dict[str, str] = {
|
HVAC_MODE_TO_DECONZ: dict[str, str] = {
|
||||||
@ -86,7 +85,6 @@ PRESET_MODE_TO_DECONZ = {
|
|||||||
DECONZ_PRESET_HOLIDAY: THERMOSTAT_PRESET_HOLIDAY,
|
DECONZ_PRESET_HOLIDAY: THERMOSTAT_PRESET_HOLIDAY,
|
||||||
DECONZ_PRESET_MANUAL: THERMOSTAT_PRESET_MANUAL,
|
DECONZ_PRESET_MANUAL: THERMOSTAT_PRESET_MANUAL,
|
||||||
}
|
}
|
||||||
|
|
||||||
DECONZ_TO_PRESET_MODE = {value: key for key, value in PRESET_MODE_TO_DECONZ.items()}
|
DECONZ_TO_PRESET_MODE = {value: key for key, value in PRESET_MODE_TO_DECONZ.items()}
|
||||||
|
|
||||||
|
|
||||||
@ -147,23 +145,29 @@ class DeconzThermostat(DeconzDevice, ClimateEntity):
|
|||||||
"""Set up thermostat device."""
|
"""Set up thermostat device."""
|
||||||
super().__init__(device, gateway)
|
super().__init__(device, gateway)
|
||||||
|
|
||||||
self.supported_hvac_modes = [
|
self._attr_hvac_modes = [
|
||||||
HVAC_MODE_HEAT,
|
HVAC_MODE_HEAT,
|
||||||
HVAC_MODE_OFF,
|
HVAC_MODE_OFF,
|
||||||
]
|
]
|
||||||
if device.mode:
|
if device.mode:
|
||||||
self.supported_hvac_modes.append(HVAC_MODE_AUTO)
|
self._attr_hvac_modes.append(HVAC_MODE_AUTO)
|
||||||
|
|
||||||
if "coolsetpoint" in device.raw["config"]:
|
if "coolsetpoint" in device.raw["config"]:
|
||||||
self.supported_hvac_modes.append(HVAC_MODE_COOL)
|
self._attr_hvac_modes.append(HVAC_MODE_COOL)
|
||||||
|
|
||||||
|
self._deconz_to_hvac_mode = {
|
||||||
|
HVAC_MODE_TO_DECONZ[item]: item for item in self._attr_hvac_modes
|
||||||
|
}
|
||||||
|
|
||||||
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
|
|
||||||
if device.fan_mode:
|
if device.fan_mode:
|
||||||
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
|
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
|
||||||
|
self._attr_fan_modes = list(FAN_MODE_TO_DECONZ)
|
||||||
|
|
||||||
if device.preset:
|
if device.preset:
|
||||||
self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
|
self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
|
||||||
|
self._attr_preset_modes = list(PRESET_MODE_TO_DECONZ)
|
||||||
|
|
||||||
# Fan control
|
# Fan control
|
||||||
|
|
||||||
@ -174,11 +178,6 @@ class DeconzThermostat(DeconzDevice, ClimateEntity):
|
|||||||
return DECONZ_TO_FAN_MODE[self._device.fan_mode]
|
return DECONZ_TO_FAN_MODE[self._device.fan_mode]
|
||||||
return DECONZ_TO_FAN_MODE[FAN_ON if self._device.state_on else FAN_OFF]
|
return DECONZ_TO_FAN_MODE[FAN_ON if self._device.state_on else FAN_OFF]
|
||||||
|
|
||||||
@property
|
|
||||||
def fan_modes(self) -> list[str]:
|
|
||||||
"""Return the list of available fan operation modes."""
|
|
||||||
return list(FAN_MODE_TO_DECONZ)
|
|
||||||
|
|
||||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
||||||
"""Set new target fan mode."""
|
"""Set new target fan mode."""
|
||||||
if fan_mode not in FAN_MODE_TO_DECONZ:
|
if fan_mode not in FAN_MODE_TO_DECONZ:
|
||||||
@ -194,21 +193,16 @@ class DeconzThermostat(DeconzDevice, ClimateEntity):
|
|||||||
|
|
||||||
Need to be one of HVAC_MODE_*.
|
Need to be one of HVAC_MODE_*.
|
||||||
"""
|
"""
|
||||||
if self._device.mode in self.supported_hvac_modes:
|
if self._device.mode in self._deconz_to_hvac_mode:
|
||||||
return HVAC_MODE_TO_DECONZ[self._device.mode]
|
return self._deconz_to_hvac_mode[self._device.mode]
|
||||||
return HVAC_MODE_HEAT if self._device.state_on else HVAC_MODE_OFF
|
return HVAC_MODE_HEAT if self._device.state_on else HVAC_MODE_OFF
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self) -> list[str]:
|
|
||||||
"""Return the list of available hvac operation modes."""
|
|
||||||
return self.supported_hvac_modes
|
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||||
"""Set new target hvac mode."""
|
"""Set new target hvac mode."""
|
||||||
if hvac_mode not in self.supported_hvac_modes:
|
if hvac_mode not in self._attr_hvac_modes:
|
||||||
raise ValueError(f"Unsupported HVAC mode {hvac_mode}")
|
raise ValueError(f"Unsupported HVAC mode {hvac_mode}")
|
||||||
|
|
||||||
if len(self.supported_hvac_modes) == 2: # Only allow turn on and off thermostat
|
if len(self._attr_hvac_modes) == 2: # Only allow turn on and off thermostat
|
||||||
await self._device.set_config(on=hvac_mode != HVAC_MODE_OFF)
|
await self._device.set_config(on=hvac_mode != HVAC_MODE_OFF)
|
||||||
else:
|
else:
|
||||||
await self._device.set_config(mode=HVAC_MODE_TO_DECONZ[hvac_mode])
|
await self._device.set_config(mode=HVAC_MODE_TO_DECONZ[hvac_mode])
|
||||||
@ -222,11 +216,6 @@ class DeconzThermostat(DeconzDevice, ClimateEntity):
|
|||||||
return DECONZ_TO_PRESET_MODE[self._device.preset]
|
return DECONZ_TO_PRESET_MODE[self._device.preset]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
|
||||||
def preset_modes(self) -> list[str]:
|
|
||||||
"""Return the list of available preset modes."""
|
|
||||||
return list(PRESET_MODE_TO_DECONZ)
|
|
||||||
|
|
||||||
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
async def async_set_preset_mode(self, preset_mode: str) -> None:
|
||||||
"""Set new preset mode."""
|
"""Set new preset mode."""
|
||||||
if preset_mode not in PRESET_MODE_TO_DECONZ:
|
if preset_mode not in PRESET_MODE_TO_DECONZ:
|
||||||
|
@ -788,3 +788,25 @@ async def test_add_new_climate_device(hass, aioclient_mock, mock_deconz_websocke
|
|||||||
assert len(hass.states.async_all()) == 2
|
assert len(hass.states.async_all()) == 2
|
||||||
assert hass.states.get("climate.thermostat").state == HVAC_MODE_AUTO
|
assert hass.states.get("climate.thermostat").state == HVAC_MODE_AUTO
|
||||||
assert hass.states.get("sensor.thermostat_battery").state == "100"
|
assert hass.states.get("sensor.thermostat_battery").state == "100"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_not_allow_clip_thermostat(hass, aioclient_mock):
|
||||||
|
"""Test that CLIP thermostats are not allowed."""
|
||||||
|
data = {
|
||||||
|
"sensors": {
|
||||||
|
"1": {
|
||||||
|
"name": "CLIP thermostat sensor",
|
||||||
|
"type": "CLIPThermostat",
|
||||||
|
"state": {},
|
||||||
|
"config": {},
|
||||||
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
|
await setup_deconz_integration(
|
||||||
|
hass, aioclient_mock, options={CONF_ALLOW_CLIP_SENSOR: False}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(hass.states.async_all()) == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user