Store Recollect Waste pickup dates in UTC (#48690)

* Store Recollect Waste pickup dates in UTC

* Code review

* Code review
This commit is contained in:
Aaron Bach 2021-04-07 23:34:47 -06:00 committed by GitHub
parent 8e6238ff61
commit e70d7327f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 13 deletions

View File

@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/recollect_waste",
"requirements": [
"aiorecollect==1.0.1"
"aiorecollect==1.0.4"
],
"codeowners": [
"@bachya"

View File

@ -8,13 +8,19 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION, CONF_FRIENDLY_NAME, CONF_NAME
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_FRIENDLY_NAME,
CONF_NAME,
DEVICE_CLASS_TIMESTAMP,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
)
from homeassistant.util.dt import as_utc
from .const import CONF_PLACE_ID, CONF_SERVICE_ID, DATA_COORDINATOR, DOMAIN, LOGGER
@ -25,7 +31,6 @@ ATTR_NEXT_PICKUP_DATE = "next_pickup_date"
DEFAULT_ATTRIBUTION = "Pickup data provided by ReCollect Waste"
DEFAULT_NAME = "recollect_waste"
DEFAULT_ICON = "mdi:trash-can-outline"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
@ -87,16 +92,16 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
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 icon(self) -> str:
"""Icon to use in the frontend."""
return DEFAULT_ICON
@property
def name(self) -> str:
"""Return the name of the sensor."""
@ -128,9 +133,8 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
"""Update the state."""
pickup_event = self.coordinator.data[0]
next_pickup_event = self.coordinator.data[1]
next_date = str(next_pickup_event.date)
self._state = pickup_event.date
self._state = as_utc(pickup_event.date).isoformat()
self._attributes.update(
{
ATTR_PICKUP_TYPES: async_get_pickup_type_names(
@ -140,6 +144,6 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
ATTR_NEXT_PICKUP_TYPES: async_get_pickup_type_names(
self._entry, next_pickup_event.pickup_types
),
ATTR_NEXT_PICKUP_DATE: next_date,
ATTR_NEXT_PICKUP_DATE: as_utc(next_pickup_event.date).isoformat(),
}
)

View File

@ -224,7 +224,7 @@ aiopvpc==2.0.2
aiopylgtv==0.4.0
# homeassistant.components.recollect_waste
aiorecollect==1.0.1
aiorecollect==1.0.4
# homeassistant.components.shelly
aioshelly==0.6.2

View File

@ -146,7 +146,7 @@ aiopvpc==2.0.2
aiopylgtv==0.4.0
# homeassistant.components.recollect_waste
aiorecollect==1.0.1
aiorecollect==1.0.4
# homeassistant.components.shelly
aioshelly==0.6.2