No-any-return

Hi

I was wondering if someone could help me with solving the following error I’m having with some of the code… the CI error shows:

Error: homeassistant/components/velbus/climate.py:74: error: Returning Any from function declared to return “HVACMode” [no-any-return]
Error: homeassistant/components/velbus/climate.py:74: error: No overload variant of “get” of “dict” matches argument type “str” [call-overload]

homeassistant/components/velbus/climate.py:74: note: Possible overload variants:
homeassistant/components/velbus/climate.py:74: note: def get(self, bool, /) → HVACMode | None

homeassistant/components/velbus/climate.py:74: note: def get(self, bool, HVACMode, /) → HVACMode

homeassistant/components/velbus/climate.py:74: note: def [_T] get(self, bool, _T, /) → HVACMode | _T

This is the code where I get the cooling mode for the thermostat…

    @property
    def hvac_mode(self) -> HVACMode:
        """Return the current hvac mode based on cool_mode message."""
        COOL_MODE_MAP = {
                    True: HVACMode.COOL,
                    False: HVACMode.HEAT,
                }
        return COOL_MODE_MAP.get(self._channel.get_cool_mode())

any idea how to rewrite this to not have an any return?

Do it like this

@property
def hvac_mode(self) -> HVACMode:
    """Return the current hvac mode based on cool_mode message."""
    return HVACMode.COOL if self._channel.get_cool_mode() else HVACMode.HEAT

Or keeping the same code, just set a type on COOL_MODE_MAP

    @property
    def hvac_mode(self) -> HVACMode:
        """Return the current hvac mode based on cool_mode message."""
        COOL_MODE_MAP: dict[bool, HVACMode] = {
                    True: HVACMode.COOL,
                    False: HVACMode.HEAT,
                }
        return COOL_MODE_MAP.get(self._channel.get_cool_mode())