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