Use climate enums in coolmaster (#70629)

This commit is contained in:
epenet 2022-04-25 13:18:34 +02:00 committed by GitHub
parent e51ed7a11b
commit 4de2730844
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,15 +1,8 @@
"""CoolMasterNet platform to control of CoolMasterNet Climate Devices."""
import logging
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import (
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
)
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.core import HomeAssistant, callback
@ -20,11 +13,11 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import CONF_SUPPORTED_MODES, DATA_COORDINATOR, DATA_INFO, DOMAIN
CM_TO_HA_STATE = {
"heat": HVAC_MODE_HEAT,
"cool": HVAC_MODE_COOL,
"auto": HVAC_MODE_HEAT_COOL,
"dry": HVAC_MODE_DRY,
"fan": HVAC_MODE_FAN_ONLY,
"heat": HVACMode.HEAT,
"cool": HVACMode.COOL,
"auto": HVACMode.HEAT_COOL,
"dry": HVACMode.DRY,
"fan": HVACMode.FAN_ONLY,
}
HA_STATE_TO_CM = {value: key for key, value in CM_TO_HA_STATE.items()}
@ -122,7 +115,7 @@ class CoolmasterClimate(CoordinatorEntity, ClimateEntity):
"""Return hvac target hvac state."""
mode = self._unit.mode
if not self._unit.is_on:
return HVAC_MODE_OFF
return HVACMode.OFF
return CM_TO_HA_STATE[mode]
@ -158,7 +151,7 @@ class CoolmasterClimate(CoordinatorEntity, ClimateEntity):
"""Set new operation mode."""
_LOGGER.debug("Setting operation mode of %s to %s", self.unique_id, hvac_mode)
if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
await self.async_turn_off()
else:
self._unit = await self._unit.set_mode(HA_STATE_TO_CM[hvac_mode])