Use climate enums in gree (#70655)

* Use climate enums in gree

* Adjust tests
This commit is contained in:
epenet 2022-04-25 10:58:39 +02:00 committed by GitHub
parent b81f8e75ee
commit 23c5bd9779
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 37 deletions

View file

@ -15,18 +15,12 @@ from greeclimate.device import (
VerticalSwing,
)
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
FAN_AUTO,
FAN_HIGH,
FAN_LOW,
FAN_MEDIUM,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_BOOST,
PRESET_ECO,
@ -36,6 +30,8 @@ from homeassistant.components.climate.const import (
SWING_HORIZONTAL,
SWING_OFF,
SWING_VERTICAL,
ClimateEntityFeature,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
@ -64,11 +60,11 @@ from .const import (
_LOGGER = logging.getLogger(__name__)
HVAC_MODES = {
Mode.Auto: HVAC_MODE_AUTO,
Mode.Cool: HVAC_MODE_COOL,
Mode.Dry: HVAC_MODE_DRY,
Mode.Fan: HVAC_MODE_FAN_ONLY,
Mode.Heat: HVAC_MODE_HEAT,
Mode.Auto: HVACMode.AUTO,
Mode.Cool: HVACMode.COOL,
Mode.Dry: HVACMode.DRY,
Mode.Fan: HVACMode.FAN_ONLY,
Mode.Heat: HVACMode.HEAT,
}
HVAC_MODES_REVERSE = {v: k for k, v in HVAC_MODES.items()}
@ -205,7 +201,7 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
def hvac_mode(self) -> str:
"""Return the current HVAC mode for the device."""
if not self.coordinator.device.power:
return HVAC_MODE_OFF
return HVACMode.OFF
return HVAC_MODES.get(self.coordinator.device.mode)
@ -220,7 +216,7 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
self._name,
)
if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
self.coordinator.device.power = False
await self.coordinator.push_state_update()
self.async_write_ha_state()
@ -253,7 +249,7 @@ class GreeClimateEntity(CoordinatorEntity, ClimateEntity):
def hvac_modes(self) -> list[str]:
"""Return the HVAC modes support by the device."""
modes = [*HVAC_MODES_REVERSE]
modes.append(HVAC_MODE_OFF)
modes.append(HVACMode.OFF)
return modes
@property

View file

@ -18,12 +18,6 @@ from homeassistant.components.climate.const import (
FAN_HIGH,
FAN_LOW,
FAN_MEDIUM,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_BOOST,
PRESET_ECO,
@ -38,6 +32,7 @@ from homeassistant.components.climate.const import (
SWING_HORIZONTAL,
SWING_OFF,
SWING_VERTICAL,
HVACMode,
)
from homeassistant.components.gree.climate import FAN_MODES_REVERSE, HVAC_MODES_REVERSE
from homeassistant.components.gree.const import FAN_MEDIUM_HIGH, FAN_MEDIUM_LOW
@ -343,7 +338,7 @@ async def test_send_power_on(hass, discovery, device, mock_now):
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.state == HVAC_MODE_OFF
assert state.state == HVACMode.OFF
async def test_send_power_off_device_timeout(hass, discovery, device, mock_now):
@ -361,7 +356,7 @@ async def test_send_power_off_device_timeout(hass, discovery, device, mock_now):
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.state == HVAC_MODE_OFF
assert state.state == HVACMode.OFF
@pytest.mark.parametrize(
@ -528,12 +523,12 @@ async def test_update_preset_mode(hass, discovery, device, mock_now, preset):
@pytest.mark.parametrize(
"hvac_mode",
(
HVAC_MODE_OFF,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVACMode.OFF,
HVACMode.AUTO,
HVACMode.COOL,
HVACMode.DRY,
HVACMode.FAN_ONLY,
HVACMode.HEAT,
),
)
async def test_send_hvac_mode(hass, discovery, device, mock_now, hvac_mode):
@ -554,7 +549,7 @@ async def test_send_hvac_mode(hass, discovery, device, mock_now, hvac_mode):
@pytest.mark.parametrize(
"hvac_mode",
(HVAC_MODE_AUTO, HVAC_MODE_COOL, HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_HEAT),
(HVACMode.AUTO, HVACMode.COOL, HVACMode.DRY, HVACMode.FAN_ONLY, HVACMode.HEAT),
)
async def test_send_hvac_mode_device_timeout(
hass, discovery, device, mock_now, hvac_mode
@ -579,17 +574,17 @@ async def test_send_hvac_mode_device_timeout(
@pytest.mark.parametrize(
"hvac_mode",
(
HVAC_MODE_OFF,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVACMode.OFF,
HVACMode.AUTO,
HVACMode.COOL,
HVACMode.DRY,
HVACMode.FAN_ONLY,
HVACMode.HEAT,
),
)
async def test_update_hvac_mode(hass, discovery, device, mock_now, hvac_mode):
"""Test for updating hvac mode from the device."""
device().power = hvac_mode != HVAC_MODE_OFF
device().power = hvac_mode != HVACMode.OFF
device().mode = HVAC_MODES_REVERSE.get(hvac_mode)
await async_setup_gree(hass)