Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add override decorators to sensor #94998

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeassistant/components/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from math import ceil, floor, isfinite, log10
from typing import Any, Final, Self, cast, final

from typing_extensions import override

from homeassistant.config_entries import ConfigEntry

# pylint: disable-next=hass-deprecated-import
Expand Down Expand Up @@ -262,6 +264,7 @@ def _default_to_device_class_name(self) -> bool:
return self.device_class not in (None, SensorDeviceClass.ENUM)

@property
@override
def device_class(self) -> SensorDeviceClass | None:
"""Return the class of this entity."""
if hasattr(self, "_attr_device_class"):
Expand Down Expand Up @@ -317,6 +320,7 @@ def last_reset(self) -> datetime | None:
return None

@property
@override
def capability_attributes(self) -> Mapping[str, Any] | None:
"""Return the capability attributes."""
if state_class := self.state_class:
Expand Down Expand Up @@ -362,6 +366,7 @@ def get_initial_entity_options(self) -> er.EntityOptionsType | None:

@final
@property
@override
def state_attributes(self) -> dict[str, Any] | None:
"""Return state attributes."""
if last_reset := self.last_reset:
Expand Down Expand Up @@ -439,6 +444,7 @@ def suggested_unit_of_measurement(self) -> str | None:

@final
@property
@override
def unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of the entity, after unit conversion."""
# Highest priority, for registered entities: unit set by user,with fallback to
Expand Down Expand Up @@ -468,6 +474,7 @@ def unit_of_measurement(self) -> str | None:

@final
@property
@override
def state(self) -> Any:
"""Return the state of the sensor and perform unit conversions, if needed."""
native_unit_of_measurement = self.native_unit_of_measurement
Expand Down