Use climate enums in venstar (#70749)
This commit is contained in:
parent
9009b1ef7d
commit
20f7e2f4d2
2 changed files with 29 additions and 45 deletions
|
@ -3,27 +3,18 @@ from __future__ import annotations
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
|
||||||
PLATFORM_SCHEMA,
|
|
||||||
ClimateEntity,
|
|
||||||
ClimateEntityFeature,
|
|
||||||
)
|
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
ATTR_HVAC_MODE,
|
ATTR_HVAC_MODE,
|
||||||
ATTR_TARGET_TEMP_HIGH,
|
ATTR_TARGET_TEMP_HIGH,
|
||||||
ATTR_TARGET_TEMP_LOW,
|
ATTR_TARGET_TEMP_LOW,
|
||||||
CURRENT_HVAC_COOL,
|
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
CURRENT_HVAC_OFF,
|
|
||||||
FAN_AUTO,
|
FAN_AUTO,
|
||||||
FAN_ON,
|
FAN_ON,
|
||||||
HVAC_MODE_AUTO,
|
|
||||||
HVAC_MODE_COOL,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
PRESET_AWAY,
|
PRESET_AWAY,
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -115,6 +106,8 @@ async def async_setup_platform(
|
||||||
class VenstarThermostat(VenstarEntity, ClimateEntity):
|
class VenstarThermostat(VenstarEntity, ClimateEntity):
|
||||||
"""Representation of a Venstar thermostat."""
|
"""Representation of a Venstar thermostat."""
|
||||||
|
|
||||||
|
_attr_hvac_modes = VALID_THERMOSTAT_MODES
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
venstar_data_coordinator: VenstarDataUpdateCoordinator,
|
venstar_data_coordinator: VenstarDataUpdateCoordinator,
|
||||||
|
@ -123,9 +116,9 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
||||||
"""Initialize the thermostat."""
|
"""Initialize the thermostat."""
|
||||||
super().__init__(venstar_data_coordinator, config)
|
super().__init__(venstar_data_coordinator, config)
|
||||||
self._mode_map = {
|
self._mode_map = {
|
||||||
HVAC_MODE_HEAT: self._client.MODE_HEAT,
|
HVACMode.HEAT: self._client.MODE_HEAT,
|
||||||
HVAC_MODE_COOL: self._client.MODE_COOL,
|
HVACMode.COOL: self._client.MODE_COOL,
|
||||||
HVAC_MODE_AUTO: self._client.MODE_AUTO,
|
HVACMode.AUTO: self._client.MODE_AUTO,
|
||||||
}
|
}
|
||||||
self._attr_unique_id = config.entry_id
|
self._attr_unique_id = config.entry_id
|
||||||
self._attr_name = self._client.name
|
self._attr_name = self._client.name
|
||||||
|
@ -168,11 +161,6 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
||||||
"""Return the list of available fan modes."""
|
"""Return the list of available fan modes."""
|
||||||
return VALID_FAN_STATES
|
return VALID_FAN_STATES
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self):
|
|
||||||
"""Return the list of available operation modes."""
|
|
||||||
return VALID_THERMOSTAT_MODES
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
|
@ -184,26 +172,26 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
||||||
return self._client.get_indoor_humidity()
|
return self._client.get_indoor_humidity()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self):
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""Return current operation mode ie. heat, cool, auto."""
|
"""Return current operation mode ie. heat, cool, auto."""
|
||||||
if self._client.mode == self._client.MODE_HEAT:
|
if self._client.mode == self._client.MODE_HEAT:
|
||||||
return HVAC_MODE_HEAT
|
return HVACMode.HEAT
|
||||||
if self._client.mode == self._client.MODE_COOL:
|
if self._client.mode == self._client.MODE_COOL:
|
||||||
return HVAC_MODE_COOL
|
return HVACMode.COOL
|
||||||
if self._client.mode == self._client.MODE_AUTO:
|
if self._client.mode == self._client.MODE_AUTO:
|
||||||
return HVAC_MODE_AUTO
|
return HVACMode.AUTO
|
||||||
return HVAC_MODE_OFF
|
return HVACMode.OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self):
|
def hvac_action(self) -> HVACAction:
|
||||||
"""Return current operation mode ie. heat, cool, auto."""
|
"""Return current operation mode ie. heat, cool, auto."""
|
||||||
if self._client.state == self._client.STATE_IDLE:
|
if self._client.state == self._client.STATE_IDLE:
|
||||||
return CURRENT_HVAC_IDLE
|
return HVACAction.IDLE
|
||||||
if self._client.state == self._client.STATE_HEATING:
|
if self._client.state == self._client.STATE_HEATING:
|
||||||
return CURRENT_HVAC_HEAT
|
return HVACAction.HEATING
|
||||||
if self._client.state == self._client.STATE_COOLING:
|
if self._client.state == self._client.STATE_COOLING:
|
||||||
return CURRENT_HVAC_COOL
|
return HVACAction.COOLING
|
||||||
return CURRENT_HVAC_OFF
|
return HVACAction.OFF
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fan_mode(self):
|
def fan_mode(self):
|
||||||
|
@ -272,13 +260,13 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
||||||
"""Return valid preset modes."""
|
"""Return valid preset modes."""
|
||||||
return [PRESET_NONE, PRESET_AWAY, HOLD_MODE_TEMPERATURE]
|
return [PRESET_NONE, PRESET_AWAY, HOLD_MODE_TEMPERATURE]
|
||||||
|
|
||||||
def _set_operation_mode(self, operation_mode):
|
def _set_operation_mode(self, operation_mode: HVACMode):
|
||||||
"""Change the operation mode (internal)."""
|
"""Change the operation mode (internal)."""
|
||||||
if operation_mode == HVAC_MODE_HEAT:
|
if operation_mode == HVACMode.HEAT:
|
||||||
success = self._client.set_mode(self._client.MODE_HEAT)
|
success = self._client.set_mode(self._client.MODE_HEAT)
|
||||||
elif operation_mode == HVAC_MODE_COOL:
|
elif operation_mode == HVACMode.COOL:
|
||||||
success = self._client.set_mode(self._client.MODE_COOL)
|
success = self._client.set_mode(self._client.MODE_COOL)
|
||||||
elif operation_mode == HVAC_MODE_AUTO:
|
elif operation_mode == HVACMode.AUTO:
|
||||||
success = self._client.set_mode(self._client.MODE_AUTO)
|
success = self._client.set_mode(self._client.MODE_AUTO)
|
||||||
else:
|
else:
|
||||||
success = self._client.set_mode(self._client.MODE_OFF)
|
success = self._client.set_mode(self._client.MODE_OFF)
|
||||||
|
@ -337,7 +325,7 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
||||||
_LOGGER.error("Failed to change the fan mode")
|
_LOGGER.error("Failed to change the fan mode")
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode):
|
def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set new target operation mode."""
|
"""Set new target operation mode."""
|
||||||
self._set_operation_mode(hvac_mode)
|
self._set_operation_mode(hvac_mode)
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
"""The climate tests for the venstar integration."""
|
"""The climate tests for the venstar integration."""
|
||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import ClimateEntityFeature
|
||||||
SUPPORT_FAN_MODE,
|
|
||||||
SUPPORT_PRESET_MODE,
|
|
||||||
SUPPORT_TARGET_HUMIDITY,
|
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .util import async_init_integration, mock_venstar_devices
|
from .util import async_init_integration, mock_venstar_devices
|
||||||
|
|
||||||
EXPECTED_BASE_SUPPORTED_FEATURES = (
|
EXPECTED_BASE_SUPPORTED_FEATURES = (
|
||||||
SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE
|
ClimateEntityFeature.TARGET_TEMPERATURE
|
||||||
|
| ClimateEntityFeature.FAN_MODE
|
||||||
|
| ClimateEntityFeature.PRESET_MODE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +41,7 @@ async def test_colortouch(hass):
|
||||||
"hvac_mode": 0,
|
"hvac_mode": 0,
|
||||||
"friendly_name": "COLORTOUCH",
|
"friendly_name": "COLORTOUCH",
|
||||||
"supported_features": EXPECTED_BASE_SUPPORTED_FEATURES
|
"supported_features": EXPECTED_BASE_SUPPORTED_FEATURES
|
||||||
| SUPPORT_TARGET_HUMIDITY,
|
| ClimateEntityFeature.TARGET_HUMIDITY,
|
||||||
}
|
}
|
||||||
# Only test for a subset of attributes in case
|
# Only test for a subset of attributes in case
|
||||||
# HA changes the implementation and a new one appears
|
# HA changes the implementation and a new one appears
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue