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:
Robert Hillis 2021-07-05 04:37:00 -04:00 committed by GitHub
parent 79ee112490
commit 6d9628423c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -109,38 +109,26 @@ async def async_setup_platform(
class AfterShipSensor(SensorEntity):
"""Representation of a AfterShip sensor."""
_attr_unit_of_measurement: str = "packages"
_attr_icon: str = ICON
def __init__(self, aftership: Tracking, name: str) -> None:
"""Initialize the sensor."""
self._attributes: dict[str, Any] = {}
self._name: str = name
self._state: int | None = None
self.aftership = aftership
@property
def name(self) -> str:
"""Return the name of the sensor."""
return self._name
self._attr_name = name
@property
def state(self) -> int | None:
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self) -> str:
"""Return the unit of measurement of this entity, if any."""
return "packages"
@property
def extra_state_attributes(self) -> dict[str, str]:
"""Return attributes for the sensor."""
return self._attributes
@property
def icon(self) -> str:
"""Icon to use in the frontend."""
return ICON
async def async_added_to_hass(self) -> None:
"""Register callbacks."""
self.async_on_remove(