1 """CoolMasterNet platform to control of CoolMasterNet Climate Devices."""
3 from __future__
import annotations
8 from pycoolmasternet_async
import SWING_MODES
21 from .const
import CONF_SUPPORTED_MODES, DATA_COORDINATOR, DATA_INFO, DOMAIN
22 from .entity
import CoolmasterEntity
25 "heat": HVACMode.HEAT,
26 "cool": HVACMode.COOL,
27 "auto": HVACMode.HEAT_COOL,
29 "fan": HVACMode.FAN_ONLY,
32 HA_STATE_TO_CM = {value: key
for key, value
in CM_TO_HA_STATE.items()}
34 FAN_MODES = [
"low",
"med",
"high",
"auto"]
36 _LOGGER = logging.getLogger(__name__)
41 config_entry: ConfigEntry,
42 async_add_entities: AddEntitiesCallback,
44 """Set up the CoolMasterNet climate platform."""
45 info = hass.data[DOMAIN][config_entry.entry_id][DATA_INFO]
46 coordinator = hass.data[DOMAIN][config_entry.entry_id][DATA_COORDINATOR]
47 supported_modes = config_entry.data.get(CONF_SUPPORTED_MODES)
50 for unit_id
in coordinator.data
55 """Representation of a coolmaster climate device."""
58 _enable_turn_on_off_backwards_compatibility =
False
60 def __init__(self, coordinator, unit_id, info, supported_modes):
61 """Initialize the climate device."""
62 super().
__init__(coordinator, unit_id, info)
68 """Return the list of supported features."""
69 supported_features = (
70 ClimateEntityFeature.TARGET_TEMPERATURE
71 | ClimateEntityFeature.FAN_MODE
72 | ClimateEntityFeature.TURN_OFF
73 | ClimateEntityFeature.TURN_ON
76 supported_features |= ClimateEntityFeature.SWING_MODE
77 return supported_features
81 """Return the unit of measurement."""
82 if self.
_unit_unit_unit.temperature_unit ==
"celsius":
83 return UnitOfTemperature.CELSIUS
85 return UnitOfTemperature.FAHRENHEIT
89 """Return the current temperature."""
94 """Return the temperature we are trying to reach."""
99 """Return hvac target hvac state."""
104 return CM_TO_HA_STATE[mode]
108 """Return the fan setting."""
113 """Return the list of available fan modes."""
118 """Return the swing mode setting."""
123 """Return swing modes if supported."""
127 """Set new target temperatures."""
128 if (temp := kwargs.get(ATTR_TEMPERATURE))
is not None:
129 _LOGGER.debug(
"Setting temp of %s to %s", self.
unique_idunique_id,
str(temp))
134 """Set new fan mode."""
135 _LOGGER.debug(
"Setting fan mode of %s to %s", self.
unique_idunique_id, fan_mode)
140 """Set new swing mode."""
141 _LOGGER.debug(
"Setting swing mode of %s to %s", self.
unique_idunique_id, swing_mode)
144 except ValueError
as error:
149 """Set new operation mode."""
150 _LOGGER.debug(
"Setting operation mode of %s to %s", self.
unique_idunique_id, hvac_mode)
152 if hvac_mode == HVACMode.OFF:
160 _LOGGER.debug(
"Turning %s on", self.
unique_idunique_id)
166 _LOGGER.debug(
"Turning %s off", self.
unique_idunique_id)
str|None swing_mode(self)
None async_turn_off(self)
str temperature_unit(self)
None async_set_fan_mode(self, str fan_mode)
None async_set_hvac_mode(self, HVACMode hvac_mode)
ClimateEntityFeature supported_features(self)
None async_set_temperature(self, **Any kwargs)
list[str]|None swing_modes(self)
None async_set_swing_mode(self, str swing_mode)
str|None swing_mode(self)
def target_temperature(self)
None async_turn_off(self)
def __init__(self, coordinator, unit_id, info, supported_modes)
def current_temperature(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)