Ensure ReCollect Waste shows pickups for midnight on the actual day (#55424)

This commit is contained in:
Aaron Bach 2021-08-29 21:27:34 -06:00 committed by GitHub
parent ebc2a0103e
commit 94e0db8ec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,8 @@
"""Support for ReCollect Waste sensors."""
from __future__ import annotations
from datetime import date, datetime, time
from aiorecollect.client import PickupType
from homeassistant.components.sensor import SensorEntity
@ -17,6 +19,7 @@ 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
@ -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(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
@ -94,7 +103,9 @@ 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_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()