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

Code before:
        """Initialize Thermostat."""
        super().__init__(coordinator)
        self._thermostat = nasweb_thermostat
        self._attr_temperature_unit = UnitOfTemperature.CELSIUS
        self._attr_precision = 1.0
        self._attr_supported_features = ClimateEntityFeature(
            ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
        )
        self._attr_available = False
        self._attr_hvac_modes = [
            HVACMode.OFF,
            HVACMode.HEAT,
            HVACMode.COOL,
            HVACMode.HEAT_COOL,
            HVACMode.FAN_ONLY,
        ]
        self._attr_name = nasweb_thermostat.name
        self._attr_target_temperature_step = 1.0
        self._attr_min_temp = -50
        self._attr_max_temp = 50
        self._attr_has_entity_name = True
        self._attr_should_poll = False
        self._attr_unique_id = f"{DOMAIN}.{self._thermostat.webio_serial}.thermostat"
        self._attr_device_info = DeviceInfo(
            identifiers={(DOMAIN, self._thermostat.webio_serial)}
        )

    async def async_added_to_hass(self) -> None:
        """When entity is added to hass."""
        await super().async_added_to_hass()
        self._handle_coordinator_update()

    def _set_attr_available(
        self, entity_last_update: float, available: bool | None
    ) -> None:
        if (
            self.coordinator.last_update is None
            or time.time() - entity_last_update >= STATUS_UPDATE_MAX_TIME_INTERVAL
        ):
            self._attr_available = False
        else:
            self._attr_available = available if available is not None else False

    @callback
    def _handle_coordinator_update(self) -> None:
        """Handle updated data from the coordinator."""
        self._attr_current_temperature = self._thermostat.current_temp
        self._attr_target_temperature_low = self._thermostat.temp_target_min
        self._attr_target_temperature_high = self._thermostat.temp_target_max
        self._attr_hvac_mode = self._get_current_hvac_mode()
        self._attr_hvac_action = self._get_current_action()

Review comment (suggestion):
```suggestion
        self._thermostat = nasweb_thermostat
        self._attr_available = False
        self._attr_name = nasweb_thermostat.name
        self._attr_unique_id = f"{DOMAIN}.{self._thermostat.webio_serial}.thermostat"
        self._attr_device_info = DeviceInfo(
            identifiers={(DOMAIN, self._thermostat.webio_serial)}
        )
```

Code after:
    ]
    _attr_max_temp = 50
    _attr_min_temp = -50
    _attr_precision = 1.0
    _attr_should_poll = False
    _attr_supported_features = ClimateEntityFeature(
        ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
    )
    _attr_target_temperature_step = 1.0
    _attr_temperature_unit = UnitOfTemperature.CELSIUS
    _attr_translation_key = CLIMATE_TRANSLATION_KEY

    def __init__(
        self,
        coordinator: BaseDataUpdateCoordinatorProtocol,
        nasweb_thermostat: NASwebThermostat,
    ) -> None:
        """Initialize Thermostat."""
        super().__init__(coordinator)
        self._thermostat = nasweb_thermostat
        self._attr_available = False
        self._attr_name = nasweb_thermostat.name
        self._attr_unique_id = f"{DOMAIN}.{self._thermostat.webio_serial}.thermostat"
        self._attr_device_info = DeviceInfo(
            identifiers={(DOMAIN, self._thermostat.webio_serial)}
        )

    async def async_added_to_hass(self) -> None:
        """When entity is added to hass."""
        await super().async_added_to_hass()
        self._handle_coordinator_update()

    def _set_attr_available(
        self, entity_last_update: float, available: bool | None
    ) -> None:
        if (
            self.coordinator.last_update is None
            or time.time() - entity_last_update >= STATUS_UPDATE_MAX_TIME_INTERVAL
        ):
            self._attr_available = False
        else:
            self._attr_available = available if available is not None else False

    @callback
    def _handle_coordinator_update(self) -> None:
        """Handle updated data from the coordinator."""
        self._attr_current_temperature = self._thermostat.current_temp
        self._attr_target_temperature_low = self._thermostat.temp_target_min
        self._attr_target_temperature_high = self._thermostat.temp_target_max
        self._attr_hvac_mode = self._get_current_hvac_mode()
        self._attr_hvac_action = self._get_current_action()