mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Fix deConz thermostat integration (#26267)
* Fixed logger name to allow selective logging * Fixed thermostat mode ('off' and 'heat' modes were not consistent with Eurotronic Spirit Zigbee Thermostat state) and added 'auto' to supported mode * Added required blank lines in code * Black formatting * Revert logging code added to each files. Instead, only replaced "." by __package__ in const.py * Added a test on self._device.state_on to determine hvac_mode * Black formatting * Added debug message when unsupported hvac_mode is encountered * Applied formatting recommandations * Updated tests for 'auto' hvac_mode
This commit is contained in:
parent
ad6ede9ef7
commit
62338dd28e
@ -3,6 +3,7 @@ from pydeconz.sensor import Thermostat
|
||||
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
HVAC_MODE_AUTO,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
@ -15,7 +16,7 @@ from .const import ATTR_OFFSET, ATTR_VALVE, NEW_SENSOR
|
||||
from .deconz_device import DeconzDevice
|
||||
from .gateway import get_gateway_from_config_entry
|
||||
|
||||
SUPPORT_HVAC = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
||||
SUPPORT_HVAC = [HVAC_MODE_AUTO, HVAC_MODE_HEAT, HVAC_MODE_OFF]
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
@ -68,7 +69,9 @@ class DeconzThermostat(DeconzDevice, ClimateDevice):
|
||||
|
||||
Need to be one of HVAC_MODE_*.
|
||||
"""
|
||||
if self._device.on:
|
||||
if self._device.mode in SUPPORT_HVAC:
|
||||
return self._device.mode
|
||||
if self._device.state_on:
|
||||
return HVAC_MODE_HEAT
|
||||
return HVAC_MODE_OFF
|
||||
|
||||
@ -101,8 +104,10 @@ class DeconzThermostat(DeconzDevice, ClimateDevice):
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode):
|
||||
"""Set new target hvac mode."""
|
||||
if hvac_mode == HVAC_MODE_HEAT:
|
||||
if hvac_mode == HVAC_MODE_AUTO:
|
||||
data = {"mode": "auto"}
|
||||
elif hvac_mode == HVAC_MODE_HEAT:
|
||||
data = {"mode": "heat"}
|
||||
elif hvac_mode == HVAC_MODE_OFF:
|
||||
data = {"mode": "off"}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Constants for the deCONZ component."""
|
||||
import logging
|
||||
|
||||
_LOGGER = logging.getLogger(".")
|
||||
_LOGGER = logging.getLogger(__package__)
|
||||
|
||||
DOMAIN = "deconz"
|
||||
|
||||
|
@ -118,13 +118,23 @@ async def test_climate_devices(hass):
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": "climate.climate_1_name", "hvac_mode": "heat"},
|
||||
{"entity_id": "climate.climate_1_name", "hvac_mode": "auto"},
|
||||
blocking=True,
|
||||
)
|
||||
gateway.api.session.put.assert_called_with(
|
||||
"http://1.2.3.4:80/api/ABCDEF/sensors/1/config", data='{"mode": "auto"}'
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
{"entity_id": "climate.climate_1_name", "hvac_mode": "heat"},
|
||||
blocking=True,
|
||||
)
|
||||
gateway.api.session.put.assert_called_with(
|
||||
"http://1.2.3.4:80/api/ABCDEF/sensors/1/config", data='{"mode": "heat"}'
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"climate",
|
||||
"set_hvac_mode",
|
||||
@ -145,7 +155,7 @@ async def test_climate_devices(hass):
|
||||
"http://1.2.3.4:80/api/ABCDEF/sensors/1/config", data='{"heatsetpoint": 2000.0}'
|
||||
)
|
||||
|
||||
assert len(gateway.api.session.put.mock_calls) == 3
|
||||
assert len(gateway.api.session.put.mock_calls) == 4
|
||||
|
||||
|
||||
async def test_verify_state_update(hass):
|
||||
@ -154,7 +164,7 @@ async def test_verify_state_update(hass):
|
||||
assert "climate.climate_1_name" in gateway.deconz_ids
|
||||
|
||||
thermostat = hass.states.get("climate.climate_1_name")
|
||||
assert thermostat.state == "off"
|
||||
assert thermostat.state == "auto"
|
||||
|
||||
state_update = {
|
||||
"t": "event",
|
||||
@ -169,7 +179,7 @@ async def test_verify_state_update(hass):
|
||||
assert len(hass.states.async_all()) == 1
|
||||
|
||||
thermostat = hass.states.get("climate.climate_1_name")
|
||||
assert thermostat.state == "off"
|
||||
assert thermostat.state == "auto"
|
||||
assert gateway.api.sensors["1"].changed_keys == {"state", "r", "t", "on", "e", "id"}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user