Correct humidifier detection in venstar component and add tests (#50439)

As of version 0.14, the venstar_colortouch lib always initializes hum_setpoint to None. When a thermostat actually reports a humidifier state, this value is replaced with the integer value of the setpoint. This changeset corrects the humidifier detection as well as adds basic test cases for the Venstar component.
This commit is contained in:
Nash Kaminski 2021-05-24 09:41:37 -05:00 committed by GitHub
parent c74e65ac2d
commit 2ae91bf0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 149 additions and 3 deletions

View File

@ -124,7 +124,7 @@ class VenstarThermostat(ClimateEntity):
if self._client.mode == self._client.MODE_AUTO:
features |= SUPPORT_TARGET_TEMPERATURE_RANGE
if self._humidifier and hasattr(self._client, "hum_active"):
if self._humidifier and self._client.hum_setpoint is not None:
features |= SUPPORT_TARGET_HUMIDITY
return features

View File

@ -2,7 +2,7 @@
"domain": "venstar",
"name": "Venstar",
"documentation": "https://www.home-assistant.io/integrations/venstar",
"requirements": ["venstarcolortouch==0.13"],
"requirements": ["venstarcolortouch==0.14"],
"codeowners": [],
"iot_class": "local_polling"
}

View File

@ -2308,7 +2308,7 @@ uvcclient==0.11.0
vallox-websocket-api==2.4.0
# homeassistant.components.venstar
venstarcolortouch==0.13
venstarcolortouch==0.14
# homeassistant.components.vilfo
vilfo-api-client==0.3.2

View File

@ -1243,6 +1243,9 @@ url-normalize==1.4.1
# homeassistant.components.uvc
uvcclient==0.11.0
# homeassistant.components.venstar
venstarcolortouch==0.14
# homeassistant.components.vilfo
vilfo-api-client==0.3.2

View File

@ -0,0 +1 @@
"""Tests for the venstar integration."""

View File

@ -0,0 +1,79 @@
"""The climate tests for the venstar integration."""
from homeassistant.components.climate.const import (
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_HUMIDITY,
SUPPORT_TARGET_TEMPERATURE,
)
from .util import async_init_integration, mock_venstar_devices
EXPECTED_BASE_SUPPORTED_FEATURES = (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE
)
@mock_venstar_devices
async def test_colortouch(hass):
"""Test interfacing with a venstar colortouch with attached humidifier."""
await async_init_integration(hass)
state = hass.states.get("climate.colortouch")
assert state.state == "heat"
expected_attributes = {
"hvac_modes": ["heat", "cool", "off", "auto"],
"min_temp": 7,
"max_temp": 35,
"min_humidity": 0,
"max_humidity": 60,
"fan_modes": ["on", "auto"],
"preset_modes": ["none", "away", "temperature"],
"current_temperature": 21.0,
"temperature": 20.5,
"current_humidity": 41,
"humidity": 30,
"fan_mode": "auto",
"hvac_action": "idle",
"preset_mode": "temperature",
"fan_state": 0,
"hvac_mode": 0,
"friendly_name": "COLORTOUCH",
"supported_features": EXPECTED_BASE_SUPPORTED_FEATURES
| SUPPORT_TARGET_HUMIDITY,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
assert all(item in state.attributes.items() for item in expected_attributes.items())
@mock_venstar_devices
async def test_t2000(hass):
"""Test interfacing with a venstar T2000 presently turned off."""
await async_init_integration(hass)
state = hass.states.get("climate.t2000")
assert state.state == "off"
expected_attributes = {
"hvac_modes": ["heat", "cool", "off", "auto"],
"min_temp": 7,
"max_temp": 35,
"fan_modes": ["on", "auto"],
"preset_modes": ["none", "away", "temperature"],
"current_temperature": 14.0,
"temperature": None,
"fan_mode": "auto",
"hvac_action": "idle",
"preset_mode": "temperature",
"fan_state": 0,
"hvac_mode": 0,
"friendly_name": "T2000",
"supported_features": EXPECTED_BASE_SUPPORTED_FEATURES,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
assert all(item in state.attributes.items() for item in expected_attributes.items())

View File

@ -0,0 +1,57 @@
"""Tests for the venstar integration."""
import requests_mock
from homeassistant.components.climate.const import DOMAIN
from homeassistant.const import CONF_HOST, CONF_PLATFORM
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from tests.common import load_fixture
TEST_MODELS = ["t2k", "colortouch"]
def mock_venstar_devices(f):
"""Decorate function to mock a Venstar Colortouch and T2000 thermostat API."""
async def wrapper(hass):
# Mock thermostats are:
# Venstar T2000, FW 4.38
# Venstar "colortouch" T7850, FW 5.1
with requests_mock.mock() as m:
for model in TEST_MODELS:
m.get(
f"http://venstar-{model}.localdomain/",
text=load_fixture(f"venstar/{model}_root.json"),
)
m.get(
f"http://venstar-{model}.localdomain/query/info",
text=load_fixture(f"venstar/{model}_info.json"),
)
m.get(
f"http://venstar-{model}.localdomain/query/sensors",
text=load_fixture(f"venstar/{model}_sensors.json"),
)
return await f(hass)
return wrapper
async def async_init_integration(
hass: HomeAssistant,
skip_setup: bool = False,
):
"""Set up the venstar integration in Home Assistant."""
platform_config = []
for model in TEST_MODELS:
platform_config.append(
{
CONF_PLATFORM: "venstar",
CONF_HOST: f"venstar-{model}.localdomain",
}
)
config = {DOMAIN: platform_config}
await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()

View File

@ -0,0 +1 @@
{"name":"COLORTOUCH","mode":1,"state":0,"fan":0,"fanstate":0,"tempunits":0,"schedule":0,"schedulepart":255,"away":0,"spacetemp":71.0,"heattemp":69.0,"cooltemp":74.0,"cooltempmin":35.0,"cooltempmax":99.0,"heattempmin":35.00,"heattempmax":99.0,"activestage":0,"hum_active":0,"hum":41,"hum_setpoint":30,"dehum_setpoint":99,"setpointdelta":2.0,"availablemodes":0}

View File

@ -0,0 +1 @@
{"api_ver":7,"type":"residential","model":"COLORTOUCH","firmware":"5.1"}

View File

@ -0,0 +1 @@
{"sensors":[{"name":"Thermostat","temp":70.0,"hum":41},{"name":"Space Temp","temp":70.0}]}

1
tests/fixtures/venstar/t2k_info.json vendored Normal file
View File

@ -0,0 +1 @@
{"name":"T2000","mode":0,"state":0,"activestage":0,"fan":0,"fanstate":0,"tempunits":0,"schedule":0,"schedulepart":1,"away":0,"spacetemp":14.5,"heattemp":10.0,"cooltemp":29.5,"cooltempmin":2.0,"cooltempmax":37.0,"heattempmin":2.0,"heattempmax":37.0,"setpointdelta":2,"availablemodes":2}

1
tests/fixtures/venstar/t2k_root.json vendored Normal file
View File

@ -0,0 +1 @@
{"api_ver": 7, "type": "residential", "model": "T2000", "firmware": "4.38"}

View File

@ -0,0 +1 @@
{"sensors": [{"name":"Thermostat","temp":14},{"name":"Space Temp","temp":14}]}