Repository: home-assistant/core
File: homeassistant/components/coolmaster/climate.py (Python)

Code before:
    FAN_MEDIUM,
    ClimateEntity,
    ClimateEntityFeature,
    HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .const import CONF_SUPPORTED_MODES
from .coordinator import CoolmasterConfigEntry, CoolmasterDataUpdateCoordinator
from .entity import CoolmasterEntity

CM_TO_HA_STATE = {
    "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()}

# these are modes supported by Coolmaster that have no direct HA equivalent.
COOLMASTER_ONLY_MODES = ["vlow", "top"]

CM_TO_HA_FAN = {
    "low": FAN_LOW,
    "med": FAN_MEDIUM,
    "high": FAN_HIGH,
    "auto": FAN_AUTO,
} | {mode: mode for mode in COOLMASTER_ONLY_MODES}

HA_FAN_TO_CM = {value: key for key, value in CM_TO_HA_FAN.items()}

FAN_MODES = list(CM_TO_HA_FAN.values())

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: CoolmasterConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up the CoolMasterNet climate platform."""
    coordinator = config_entry.runtime_data
    supported_modes: list[str] = config_entry.data[CONF_SUPPORTED_MODES]
    async_add_entities(
        CoolmasterClimate(

Review comment (suggestion):
On 2nd thought, I think we should just fall back to the coolmaster mode if it's not in `CM_TO_HA_FAN`. While `vlow` and `top` seem to be the only states today, we don't know what's going to happen in the future (or if there were any others in past models).
Something like
```python
CM_TO_HA_FAN.get(self._unit.fan_speed, self._unit.fan_speed)
```


Code after:
    FAN_MEDIUM,
    ClimateEntity,
    ClimateEntityFeature,
    HVACMode,
)
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .const import CONF_SUPPORTED_MODES
from .coordinator import CoolmasterConfigEntry, CoolmasterDataUpdateCoordinator
from .entity import CoolmasterEntity

CM_TO_HA_STATE = {
    "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()}

CM_TO_HA_FAN = {
    "low": FAN_LOW,
    "med": FAN_MEDIUM,
    "high": FAN_HIGH,
    "auto": FAN_AUTO,
}

HA_FAN_TO_CM = {value: key for key, value in CM_TO_HA_FAN.items()}

FAN_MODES = list(CM_TO_HA_FAN.values())

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
    hass: HomeAssistant,
    config_entry: CoolmasterConfigEntry,
    async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
    """Set up the CoolMasterNet climate platform."""
    coordinator = config_entry.runtime_data
    supported_modes: list[str] = config_entry.data[CONF_SUPPORTED_MODES]
    async_add_entities(
        CoolmasterClimate(
            coordinator, unit_id, [HVACMode(mode) for mode in supported_modes]
        )
        for unit_id in coordinator.data