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

Code before:
    _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
    _attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF, HVACMode.AUTO]
    _attr_name = None

    def __init__(
        self,
        coordinator: WattsVisionDeviceCoordinator,
        thermostat: ThermostatDevice,
    ) -> None:
        """Initialize the climate entity."""
        super().__init__(coordinator, thermostat.device_id)

        self._attr_min_temp = thermostat.min_allowed_temperature
        self._attr_max_temp = thermostat.max_allowed_temperature

        if thermostat.temperature_unit.upper() == "C":
            self._attr_temperature_unit = UnitOfTemperature.CELSIUS
        else:
            self._attr_temperature_unit = UnitOfTemperature.FAHRENHEIT

    @property
    def thermostat(self) -> ThermostatDevice:
        """Return the thermostat device."""
        assert isinstance(self.device, ThermostatDevice)
        return self.device

    @property
    def current_temperature(self) -> float | None:
        """Return the current temperature."""
        return self.thermostat.current_temperature

    @property
    def target_temperature(self) -> float | None:
        """Return the temperature setpoint."""
        return self.thermostat.setpoint

    @property
    def hvac_mode(self) -> HVACMode | None:
        """Return hvac mode."""
        return THERMOSTAT_MODE_TO_HVAC.get(self.thermostat.thermostat_mode)

    async def async_set_temperature(self, **kwargs: Any) -> None:
        """Set new target temperature."""
        temperature = kwargs.get(ATTR_TEMPERATURE)
        if temperature is None:
            return

        try:
            await self.coordinator.client.set_thermostat_temperature(
                self.device_id, temperature
            )

Review comment (suggestion):
if `self.device` is always a `ThermostatDevice`, you can just do `device: ThermostatDevice` outside of the constructor

Code after:
    _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
    _attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF, HVACMode.AUTO]
    _attr_name = None

    def __init__(
        self,
        coordinator: WattsVisionDeviceCoordinator,
        thermostat: ThermostatDevice,
    ) -> None:
        """Initialize the climate entity."""
        super().__init__(coordinator, thermostat.device_id)

        self._attr_min_temp = thermostat.min_allowed_temperature
        self._attr_max_temp = thermostat.max_allowed_temperature

        if thermostat.temperature_unit.upper() == "C":
            self._attr_temperature_unit = UnitOfTemperature.CELSIUS
        else:
            self._attr_temperature_unit = UnitOfTemperature.FAHRENHEIT

    @property
    def current_temperature(self) -> float | None:
        """Return the current temperature."""
        return self.device.current_temperature

    @property
    def target_temperature(self) -> float | None:
        """Return the temperature setpoint."""
        return self.device.setpoint

    @property
    def hvac_mode(self) -> HVACMode | None:
        """Return hvac mode."""
        return THERMOSTAT_MODE_TO_HVAC.get(self.device.thermostat_mode)

    async def async_set_temperature(self, **kwargs: Any) -> None:
        """Set new target temperature."""
        temperature = kwargs.get(ATTR_TEMPERATURE)
        if temperature is None:
            return

        try:
            await self.coordinator.client.set_thermostat_temperature(
                self.device_id, temperature
            )
        except RuntimeError as err:
            raise HomeAssistantError(
                translation_domain=DOMAIN,
                translation_key="set_temperature_error",
            ) from err