Remove redundant property definitions in ReCollect Waste (#52368)
* Remove redundant property definitions in ReCollect Waste * Code review * Code review
This commit is contained in:
parent
1eb27f7ccc
commit
e435ac6fcd
2 changed files with 12 additions and 35 deletions
|
@ -84,37 +84,18 @@ async def async_setup_entry(
|
|||
class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
||||
"""ReCollect Waste Sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_TIMESTAMP
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, entry: ConfigEntry) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||
|
||||
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
|
||||
self._attr_name = DEFAULT_NAME
|
||||
self._attr_unique_id = (
|
||||
f"{entry.data[CONF_PLACE_ID]}{entry.data[CONF_SERVICE_ID]}"
|
||||
)
|
||||
self._entry = entry
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def device_class(self) -> dict:
|
||||
"""Return the device class."""
|
||||
return DEVICE_CLASS_TIMESTAMP
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
"""Return the state attributes."""
|
||||
return self._attributes
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the sensor."""
|
||||
return DEFAULT_NAME
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique ID."""
|
||||
return f"{self._entry.data[CONF_PLACE_ID]}{self._entry.data[CONF_SERVICE_ID]}"
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
|
@ -133,8 +114,7 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
|||
pickup_event = self.coordinator.data[0]
|
||||
next_pickup_event = self.coordinator.data[1]
|
||||
|
||||
self._state = as_utc(pickup_event.date).isoformat()
|
||||
self._attributes.update(
|
||||
self._attr_extra_state_attributes.update(
|
||||
{
|
||||
ATTR_PICKUP_TYPES: async_get_pickup_type_names(
|
||||
self._entry, pickup_event.pickup_types
|
||||
|
@ -146,3 +126,4 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
|||
ATTR_NEXT_PICKUP_DATE: as_utc(next_pickup_event.date).isoformat(),
|
||||
}
|
||||
)
|
||||
self._attr_state = as_utc(pickup_event.date).isoformat()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue