mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
Improve type hint in darksky sensor entity (#77035)
This commit is contained in:
parent
f329428c7f
commit
1edb68f8ba
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user