Skip to content

Commit

Permalink
Correctly support use of Farenheit in Gree Climate component (home-as…
Browse files Browse the repository at this point in the history
  • Loading branch information
cmroche authored Jun 7, 2021
1 parent aad90b8 commit bc30920
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
10 changes: 6 additions & 4 deletions homeassistant/components/gree/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import logging

from greeclimate.device import (
TEMP_MAX,
TEMP_MAX_F,
TEMP_MIN,
TEMP_MIN_F,
FanSpeed,
HorizontalSwing,
Mode,
Expand Down Expand Up @@ -55,8 +59,6 @@
DOMAIN,
FAN_MEDIUM_HIGH,
FAN_MEDIUM_LOW,
MAX_TEMP,
MIN_TEMP,
TARGET_TEMPERATURE_STEP,
)

Expand Down Expand Up @@ -184,12 +186,12 @@ async def async_set_temperature(self, **kwargs):
@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:
Expand Down
3 changes: 0 additions & 3 deletions homeassistant/components/gree/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
FAN_MEDIUM_LOW = "medium low"
FAN_MEDIUM_HIGH = "medium high"

MIN_TEMP = 16
MAX_TEMP = 30

MAX_ERRORS = 2

TARGET_TEMPERATURE_STEP = 1
2 changes: 1 addition & 1 deletion homeassistant/components/gree/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 39 additions & 9 deletions tests/components/gree/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
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
Expand Down Expand Up @@ -376,51 +378,79 @@ 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)

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(
Expand Down

0 comments on commit bc30920

Please sign in to comment.