Ensure ReCollect Waste shows pickups for midnight on the actual day (#55424)
This commit is contained in:
parent
ebc2a0103e
commit
94e0db8ec4
1 changed files with 13 additions and 2 deletions
|
@ -1,6 +1,8 @@
|
||||||
"""Support for ReCollect Waste sensors."""
|
"""Support for ReCollect Waste sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import date, datetime, time
|
||||||
|
|
||||||
from aiorecollect.client import PickupType
|
from aiorecollect.client import PickupType
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity
|
||||||
|
@ -17,6 +19,7 @@ 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
|
from .const import CONF_PLACE_ID, CONF_SERVICE_ID, DATA_COORDINATOR, DOMAIN
|
||||||
|
|
||||||
|
@ -44,6 +47,12 @@ def async_get_pickup_type_names(
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def async_get_utc_midnight(target_date: date) -> datetime:
|
||||||
|
"""Get UTC midnight for a given date."""
|
||||||
|
return as_utc(datetime.combine(target_date, time(0)))
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -94,7 +103,9 @@ 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_pickup_event.date.isoformat(),
|
ATTR_NEXT_PICKUP_DATE: async_get_utc_midnight(
|
||||||
|
next_pickup_event.date
|
||||||
|
).isoformat(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
self._attr_native_value = pickup_event.date.isoformat()
|
self._attr_native_value = async_get_utc_midnight(pickup_event.date).isoformat()
|
||||||
|
|
Loading…
Add table
Reference in a new issue