diff --git a/homeassistant/components/venstar/climate.py b/homeassistant/components/venstar/climate.py index b4d8264a3ab..72e9ecc3de4 100644 --- a/homeassistant/components/venstar/climate.py +++ b/homeassistant/components/venstar/climate.py @@ -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 diff --git a/homeassistant/components/venstar/manifest.json b/homeassistant/components/venstar/manifest.json index 0baa1e56cfa..444a3fabf9a 100644 --- a/homeassistant/components/venstar/manifest.json +++ b/homeassistant/components/venstar/manifest.json @@ -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" } diff --git a/requirements_all.txt b/requirements_all.txt index 3f3f68c9142..6dae9b586e8 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index aacef3ba5ef..4e296b34971 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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 diff --git a/tests/components/venstar/__init__.py b/tests/components/venstar/__init__.py new file mode 100644 index 00000000000..908755a585f --- /dev/null +++ b/tests/components/venstar/__init__.py @@ -0,0 +1 @@ +"""Tests for the venstar integration.""" diff --git a/tests/components/venstar/test_climate.py b/tests/components/venstar/test_climate.py new file mode 100644 index 00000000000..9461032060b --- /dev/null +++ b/tests/components/venstar/test_climate.py @@ -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()) diff --git a/tests/components/venstar/util.py b/tests/components/venstar/util.py new file mode 100644 index 00000000000..b86f8475798 --- /dev/null +++ b/tests/components/venstar/util.py @@ -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() diff --git a/tests/fixtures/venstar/colortouch_info.json b/tests/fixtures/venstar/colortouch_info.json new file mode 100644 index 00000000000..44812beb762 --- /dev/null +++ b/tests/fixtures/venstar/colortouch_info.json @@ -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} diff --git a/tests/fixtures/venstar/colortouch_root.json b/tests/fixtures/venstar/colortouch_root.json new file mode 100644 index 00000000000..820f88210b6 --- /dev/null +++ b/tests/fixtures/venstar/colortouch_root.json @@ -0,0 +1 @@ +{"api_ver":7,"type":"residential","model":"COLORTOUCH","firmware":"5.1"} \ No newline at end of file diff --git a/tests/fixtures/venstar/colortouch_sensors.json b/tests/fixtures/venstar/colortouch_sensors.json new file mode 100644 index 00000000000..a1ba04753b8 --- /dev/null +++ b/tests/fixtures/venstar/colortouch_sensors.json @@ -0,0 +1 @@ +{"sensors":[{"name":"Thermostat","temp":70.0,"hum":41},{"name":"Space Temp","temp":70.0}]} diff --git a/tests/fixtures/venstar/t2k_info.json b/tests/fixtures/venstar/t2k_info.json new file mode 100644 index 00000000000..81398dad391 --- /dev/null +++ b/tests/fixtures/venstar/t2k_info.json @@ -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} diff --git a/tests/fixtures/venstar/t2k_root.json b/tests/fixtures/venstar/t2k_root.json new file mode 100644 index 00000000000..5f7449181a6 --- /dev/null +++ b/tests/fixtures/venstar/t2k_root.json @@ -0,0 +1 @@ +{"api_ver": 7, "type": "residential", "model": "T2000", "firmware": "4.38"} \ No newline at end of file diff --git a/tests/fixtures/venstar/t2k_sensors.json b/tests/fixtures/venstar/t2k_sensors.json new file mode 100644 index 00000000000..120b5820088 --- /dev/null +++ b/tests/fixtures/venstar/t2k_sensors.json @@ -0,0 +1 @@ +{"sensors": [{"name":"Thermostat","temp":14},{"name":"Space Temp","temp":14}]} \ No newline at end of file