mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Use entity class attributes for aftership (#52500)
* Use entity class attributes for aftership * Tweaks Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
79ee112490
commit
6d9628423c
@ -109,38 +109,26 @@ async def async_setup_platform(
|
|||||||
class AfterShipSensor(SensorEntity):
|
class AfterShipSensor(SensorEntity):
|
||||||
"""Representation of a AfterShip sensor."""
|
"""Representation of a AfterShip sensor."""
|
||||||
|
|
||||||
|
_attr_unit_of_measurement: str = "packages"
|
||||||
|
_attr_icon: str = ICON
|
||||||
|
|
||||||
def __init__(self, aftership: Tracking, name: str) -> None:
|
def __init__(self, aftership: Tracking, name: str) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._attributes: dict[str, Any] = {}
|
self._attributes: dict[str, Any] = {}
|
||||||
self._name: str = name
|
|
||||||
self._state: int | None = None
|
self._state: int | None = None
|
||||||
self.aftership = aftership
|
self.aftership = aftership
|
||||||
|
self._attr_name = name
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> int | None:
|
def state(self) -> int | None:
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self) -> str:
|
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
|
||||||
return "packages"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict[str, str]:
|
def extra_state_attributes(self) -> dict[str, str]:
|
||||||
"""Return attributes for the sensor."""
|
"""Return attributes for the sensor."""
|
||||||
return self._attributes
|
return self._attributes
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Icon to use in the frontend."""
|
|
||||||
return ICON
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user