From bc30920824790030a420369fafcf7c89e4ef83a3 Mon Sep 17 00:00:00 2001 From: Clifford Roche Date: Mon, 7 Jun 2021 18:21:03 -0400 Subject: [PATCH] Correctly support use of Farenheit in Gree Climate component (#50260) --- homeassistant/components/gree/climate.py | 10 +++-- homeassistant/components/gree/const.py | 3 -- homeassistant/components/gree/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/gree/test_climate.py | 48 +++++++++++++++++---- 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/gree/climate.py b/homeassistant/components/gree/climate.py index e468195ff92..acd57ef590d 100644 --- a/homeassistant/components/gree/climate.py +++ b/homeassistant/components/gree/climate.py @@ -4,6 +4,10 @@ from __future__ import annotations import logging from greeclimate.device import ( + TEMP_MAX, + TEMP_MAX_F, + TEMP_MIN, + TEMP_MIN_F, FanSpeed, HorizontalSwing, Mode, @@ -55,8 +59,6 @@ from .const import ( DOMAIN, FAN_MEDIUM_HIGH, FAN_MEDIUM_LOW, - MAX_TEMP, - MIN_TEMP, TARGET_TEMPERATURE_STEP, ) @@ -184,12 +186,12 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity): @property def min_temp(self) -> float: """Return the minimum temperature supported by the device.""" - return MIN_TEMP + return TEMP_MIN if self.temperature_unit == TEMP_CELSIUS else TEMP_MIN_F @property def max_temp(self) -> float: """Return the maximum temperature supported by the device.""" - return MAX_TEMP + return TEMP_MAX if self.temperature_unit == TEMP_CELSIUS else TEMP_MAX_F @property def target_temperature_step(self) -> float: diff --git a/homeassistant/components/gree/const.py b/homeassistant/components/gree/const.py index 2d9a48496b2..b4df7a1acde 100644 --- a/homeassistant/components/gree/const.py +++ b/homeassistant/components/gree/const.py @@ -16,9 +16,6 @@ COORDINATOR = "coordinator" FAN_MEDIUM_LOW = "medium low" FAN_MEDIUM_HIGH = "medium high" -MIN_TEMP = 16 -MAX_TEMP = 30 - MAX_ERRORS = 2 TARGET_TEMPERATURE_STEP = 1 diff --git a/homeassistant/components/gree/manifest.json b/homeassistant/components/gree/manifest.json index 58ddb62216b..8108df18cc8 100644 --- a/homeassistant/components/gree/manifest.json +++ b/homeassistant/components/gree/manifest.json @@ -3,7 +3,7 @@ "name": "Gree Climate", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/gree", - "requirements": ["greeclimate==0.11.4"], + "requirements": ["greeclimate==0.11.7"], "codeowners": ["@cmroche"], "iot_class": "local_polling" } diff --git a/requirements_all.txt b/requirements_all.txt index 1d418b66829..74547f648a0 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -702,7 +702,7 @@ gpiozero==1.5.1 gps3==0.33.3 # homeassistant.components.gree -greeclimate==0.11.4 +greeclimate==0.11.7 # homeassistant.components.greeneye_monitor greeneye_monitor==2.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 7ed3fd8ddfe..b7016f86d9c 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -387,7 +387,7 @@ google-nest-sdm==0.2.12 googlemaps==2.5.1 # homeassistant.components.gree -greeclimate==0.11.4 +greeclimate==0.11.7 # homeassistant.components.growatt_server growattServer==1.0.1 diff --git a/tests/components/gree/test_climate.py b/tests/components/gree/test_climate.py index 62dd7ca545f..c062cfc5615 100644 --- a/tests/components/gree/test_climate.py +++ b/tests/components/gree/test_climate.py @@ -55,6 +55,8 @@ from homeassistant.const import ( SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_UNAVAILABLE, + TEMP_CELSIUS, + TEMP_FAHRENHEIT, ) from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -376,26 +378,42 @@ async def test_send_power_off_device_timeout(hass, discovery, device, mock_now): assert state.state == HVAC_MODE_OFF -async def test_send_target_temperature(hass, discovery, device, mock_now): +@pytest.mark.parametrize( + "units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)] +) +async def test_send_target_temperature(hass, discovery, device, units, temperature): """Test for sending target temperature command to the device.""" + hass.config.units.temperature_unit = units + if units == TEMP_FAHRENHEIT: + device().temperature_units = 1 + await async_setup_gree(hass) assert await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, - {ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 25.1}, + {ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: temperature}, blocking=True, ) state = hass.states.get(ENTITY_ID) assert state is not None - assert state.attributes.get(ATTR_TEMPERATURE) == 25 + assert state.attributes.get(ATTR_TEMPERATURE) == temperature + + # Reset config temperature_unit back to CELSIUS, required for additional tests outside this component. + hass.config.units.temperature_unit = TEMP_CELSIUS +@pytest.mark.parametrize( + "units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)] +) async def test_send_target_temperature_device_timeout( - hass, discovery, device, mock_now + hass, discovery, device, units, temperature ): """Test for sending target temperature command to the device with a device timeout.""" + hass.config.units.temperature_unit = units + if units == TEMP_FAHRENHEIT: + device().temperature_units = 1 device().push_state_update.side_effect = DeviceTimeoutError await async_setup_gree(hass) @@ -403,24 +421,36 @@ async def test_send_target_temperature_device_timeout( assert await hass.services.async_call( DOMAIN, SERVICE_SET_TEMPERATURE, - {ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: 25.1}, + {ATTR_ENTITY_ID: ENTITY_ID, ATTR_TEMPERATURE: temperature}, blocking=True, ) state = hass.states.get(ENTITY_ID) assert state is not None - assert state.attributes.get(ATTR_TEMPERATURE) == 25 + assert state.attributes.get(ATTR_TEMPERATURE) == temperature + + # Reset config temperature_unit back to CELSIUS, required for additional tests outside this component. + hass.config.units.temperature_unit = TEMP_CELSIUS -async def test_update_target_temperature(hass, discovery, device, mock_now): +@pytest.mark.parametrize( + "units,temperature", [(TEMP_CELSIUS, 25), (TEMP_FAHRENHEIT, 74)] +) +async def test_update_target_temperature(hass, discovery, device, units, temperature): """Test for updating target temperature from the device.""" - device().target_temperature = 32 + hass.config.units.temperature_unit = units + if units == TEMP_FAHRENHEIT: + device().temperature_units = 1 + device().target_temperature = temperature await async_setup_gree(hass) state = hass.states.get(ENTITY_ID) assert state is not None - assert state.attributes.get(ATTR_TEMPERATURE) == 32 + assert state.attributes.get(ATTR_TEMPERATURE) == temperature + + # Reset config temperature_unit back to CELSIUS, required for additional tests outside this component. + hass.config.units.temperature_unit = TEMP_CELSIUS @pytest.mark.parametrize(