Improve type hint in darksky sensor entity (#77035)

This commit is contained in:
epenet 2022-08-20 08:39:53 +02:00 committed by GitHub
parent f329428c7f
commit 1edb68f8ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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