Store Recollect Waste pickup dates in UTC (#48690)
* Store Recollect Waste pickup dates in UTC * Code review * Code review
This commit is contained in:
parent
8e6238ff61
commit
e70d7327f9
4 changed files with 17 additions and 13 deletions
|
@ -4,7 +4,7 @@
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/recollect_waste",
|
"documentation": "https://www.home-assistant.io/integrations/recollect_waste",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"aiorecollect==1.0.1"
|
"aiorecollect==1.0.4"
|
||||||
],
|
],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@bachya"
|
"@bachya"
|
||||||
|
|
|
@ -8,13 +8,19 @@ import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
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.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
)
|
)
|
||||||
|
from homeassistant.util.dt import as_utc
|
||||||
|
|
||||||
from .const import CONF_PLACE_ID, CONF_SERVICE_ID, DATA_COORDINATOR, DOMAIN, LOGGER
|
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_ATTRIBUTION = "Pickup data provided by ReCollect Waste"
|
||||||
DEFAULT_NAME = "recollect_waste"
|
DEFAULT_NAME = "recollect_waste"
|
||||||
DEFAULT_ICON = "mdi:trash-can-outline"
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
|
@ -87,16 +92,16 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
||||||
self._entry = entry
|
self._entry = entry
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> dict:
|
||||||
|
"""Return the device class."""
|
||||||
|
return DEVICE_CLASS_TIMESTAMP
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self) -> dict:
|
def extra_state_attributes(self) -> dict:
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
return self._attributes
|
return self._attributes
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self) -> str:
|
|
||||||
"""Icon to use in the frontend."""
|
|
||||||
return DEFAULT_ICON
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
|
@ -128,9 +133,8 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
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]
|
||||||
next_date = str(next_pickup_event.date)
|
|
||||||
|
|
||||||
self._state = pickup_event.date
|
self._state = as_utc(pickup_event.date).isoformat()
|
||||||
self._attributes.update(
|
self._attributes.update(
|
||||||
{
|
{
|
||||||
ATTR_PICKUP_TYPES: async_get_pickup_type_names(
|
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(
|
ATTR_NEXT_PICKUP_TYPES: async_get_pickup_type_names(
|
||||||
self._entry, next_pickup_event.pickup_types
|
self._entry, next_pickup_event.pickup_types
|
||||||
),
|
),
|
||||||
ATTR_NEXT_PICKUP_DATE: next_date,
|
ATTR_NEXT_PICKUP_DATE: as_utc(next_pickup_event.date).isoformat(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -224,7 +224,7 @@ aiopvpc==2.0.2
|
||||||
aiopylgtv==0.4.0
|
aiopylgtv==0.4.0
|
||||||
|
|
||||||
# homeassistant.components.recollect_waste
|
# homeassistant.components.recollect_waste
|
||||||
aiorecollect==1.0.1
|
aiorecollect==1.0.4
|
||||||
|
|
||||||
# homeassistant.components.shelly
|
# homeassistant.components.shelly
|
||||||
aioshelly==0.6.2
|
aioshelly==0.6.2
|
||||||
|
|
|
@ -146,7 +146,7 @@ aiopvpc==2.0.2
|
||||||
aiopylgtv==0.4.0
|
aiopylgtv==0.4.0
|
||||||
|
|
||||||
# homeassistant.components.recollect_waste
|
# homeassistant.components.recollect_waste
|
||||||
aiorecollect==1.0.1
|
aiorecollect==1.0.4
|
||||||
|
|
||||||
# homeassistant.components.shelly
|
# homeassistant.components.shelly
|
||||||
aioshelly==0.6.2
|
aioshelly==0.6.2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue