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

Code before:

    @property
    def current_temperature(self):
        """Return the current temperature."""
        return self._unit.temperature

    @property
    def target_temperature(self):
        """Return the temperature we are trying to reach."""
        return self._unit.thermostat

    @property
    def hvac_mode(self):
        """Return hvac target hvac state."""
        mode = self._unit.mode
        if not self._unit.is_on:
            return HVACMode.OFF

        return CM_TO_HA_STATE[mode]

    @property
    def fan_mode(self):
        """Return the fan setting."""
        return CM_TO_HA_FAN[self._unit.fan_speed]

    @property
    def fan_modes(self):
        """Return the list of available fan modes."""
        return FAN_MODES

    @property
    def swing_mode(self) -> str | None:
        """Return the swing mode setting."""
        return self._unit.swing

    @property
    def swing_modes(self) -> list[str] | None:
        """Return swing modes if supported."""
        return SWING_MODES if self.swing_mode is not None else None

    async def async_set_temperature(self, **kwargs: Any) -> None:
        """Set new target temperatures."""
        if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None:
            _LOGGER.debug("Setting temp of %s to %s", self.unique_id, str(temp))
            self._unit = await self._unit.set_thermostat(temp)
            self.async_write_ha_state()

    async def async_set_fan_mode(self, fan_mode: str) -> None:
        """Set new fan mode."""
        _LOGGER.debug("Setting fan mode of %s to %s", self.unique_id, fan_mode)
        self._unit = await self._unit.set_fan_speed(HA_FAN_TO_CM[fan_mode])

Review comment (suggestion):
We should not return unknown values here. 
Instead, can we add `vlow` and `top` as know values and also add translation strings for them?

(making them lowercase is fine)

Code after:

    @property
    def current_temperature(self):
        """Return the current temperature."""
        return self._unit.temperature

    @property
    def target_temperature(self):
        """Return the temperature we are trying to reach."""
        return self._unit.thermostat

    @property
    def hvac_mode(self):
        """Return hvac target hvac state."""
        mode = self._unit.mode
        if not self._unit.is_on:
            return HVACMode.OFF

        return CM_TO_HA_STATE[mode]

    @property
    def fan_mode(self):
        """Return the fan setting."""

        # Normalize to lowercase for lookup, and pass unknown values through.
        return CM_TO_HA_FAN.get(self._unit.fan_speed.lower(), self._unit.fan_speed)

    @property
    def fan_modes(self):
        """Return the list of available fan modes."""
        return FAN_MODES

    @property
    def swing_mode(self) -> str | None:
        """Return the swing mode setting."""
        return self._unit.swing

    @property
    def swing_modes(self) -> list[str] | None:
        """Return swing modes if supported."""
        return SWING_MODES if self.swing_mode is not None else None

    async def async_set_temperature(self, **kwargs: Any) -> None:
        """Set new target temperatures."""
        if (temp := kwargs.get(ATTR_TEMPERATURE)) is not None:
            _LOGGER.debug("Setting temp of %s to %s", self.unique_id, str(temp))
            self._unit = await self._unit.set_thermostat(temp)
            self.async_write_ha_state()

    async def async_set_fan_mode(self, fan_mode: str) -> None:
        """Set new fan mode."""