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
|
@ -21,14 +21,10 @@ DEFAULT_UPDATE_INTERVAL = timedelta(days=1)
|
||||||
PLATFORMS = ["sensor"]
|
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:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up RainMachine as config entry."""
|
"""Set up RainMachine as config entry."""
|
||||||
|
hass.data.setdefault(DOMAIN, {DATA_COORDINATOR: {}, DATA_LISTENER: {}})
|
||||||
|
|
||||||
session = aiohttp_client.async_get_clientsession(hass)
|
session = aiohttp_client.async_get_clientsession(hass)
|
||||||
client = Client(
|
client = Client(
|
||||||
entry.data[CONF_PLACE_ID], entry.data[CONF_SERVICE_ID], session=session
|
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):
|
class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""ReCollect Waste Sensor."""
|
"""ReCollect Waste Sensor."""
|
||||||
|
|
||||||
|
_attr_device_class = DEVICE_CLASS_TIMESTAMP
|
||||||
|
|
||||||
def __init__(self, coordinator: DataUpdateCoordinator, entry: ConfigEntry) -> None:
|
def __init__(self, coordinator: DataUpdateCoordinator, entry: ConfigEntry) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(coordinator)
|
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._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
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
|
@ -133,8 +114,7 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
||||||
pickup_event = self.coordinator.data[0]
|
pickup_event = self.coordinator.data[0]
|
||||||
next_pickup_event = self.coordinator.data[1]
|
next_pickup_event = self.coordinator.data[1]
|
||||||
|
|
||||||
self._state = as_utc(pickup_event.date).isoformat()
|
self._attr_extra_state_attributes.update(
|
||||||
self._attributes.update(
|
|
||||||
{
|
{
|
||||||
ATTR_PICKUP_TYPES: async_get_pickup_type_names(
|
ATTR_PICKUP_TYPES: async_get_pickup_type_names(
|
||||||
self._entry, pickup_event.pickup_types
|
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(),
|
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