diff --git a/homeassistant/components/darksky/sensor.py b/homeassistant/components/darksky/sensor.py index 84a0b0f23f2..db79b82de53 100644 --- a/homeassistant/components/darksky/sensor.py +++ b/homeassistant/components/darksky/sensor.py @@ -663,8 +663,7 @@ class DarkSkySensor(SensorEntity): self.forecast_data = forecast_data self.forecast_day = forecast_day self.forecast_hour = forecast_hour - self._icon = None - self._unit_of_measurement = None + self._icon: str | None = None if forecast_day is not None: self._attr_name = f"{name} {description.name} {forecast_day}d" @@ -673,18 +672,13 @@ class DarkSkySensor(SensorEntity): else: self._attr_name = f"{name} {description.name}" - @property - def native_unit_of_measurement(self): - """Return the unit of measurement of this entity, if any.""" - return self._unit_of_measurement - @property def unit_system(self): """Return the unit system of this entity.""" return self.forecast_data.unit_system @property - def entity_picture(self): + def entity_picture(self) -> str | None: """Return the entity picture to use in the frontend, if any.""" if self._icon is None or "summary" not in self.entity_description.key: return None @@ -694,13 +688,15 @@ class DarkSkySensor(SensorEntity): return None - def update_unit_of_measurement(self): + def update_unit_of_measurement(self) -> None: """Update units based on unit system.""" unit_key = MAP_UNIT_SYSTEM.get(self.unit_system, "si_unit") - self._unit_of_measurement = getattr(self.entity_description, unit_key) + self._attr_native_unit_of_measurement = getattr( + self.entity_description, unit_key + ) @property - def icon(self): + def icon(self) -> str | None: """Icon to use in the frontend, if any.""" if ( "summary" in self.entity_description.key @@ -710,7 +706,7 @@ class DarkSkySensor(SensorEntity): return self.entity_description.icon - def update(self): + def update(self) -> None: """Get the latest data from Dark Sky and updates the states.""" # Call the API for new forecast data. Each sensor will re-trigger this # same exact call, but that's fine. We cache results for a short period