mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
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
@ -21,14 +21,10 @@ DEFAULT_UPDATE_INTERVAL = timedelta(days=1)
|
||||
PLATFORMS = ["sensor"]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
||||
"""Set up the RainMachine component."""
|
||||
hass.data[DOMAIN] = {DATA_COORDINATOR: {}, DATA_LISTENER: {}}
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up RainMachine as config entry."""
|
||||
hass.data.setdefault(DOMAIN, {DATA_COORDINATOR: {}, DATA_LISTENER: {}})
|
||||
|
||||
session = aiohttp_client.async_get_clientsession(hass)
|
||||
client = Client(
|
||||
entry.data[CONF_PLACE_ID], entry.data[CONF_SERVICE_ID], session=session
|
||||
|
@ -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…
x
Reference in New Issue
Block a user