Change ReCollect Waste device class to date (#59180)

This commit is contained in:
Aaron Bach 2021-11-05 13:29:12 -06:00 committed by GitHub
parent d2ffecbca4
commit 6145ee97cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,17 +1,11 @@
"""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
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import ATTR_ATTRIBUTION, CONF_FRIENDLY_NAME, DEVICE_CLASS_DATE
ATTR_ATTRIBUTION,
CONF_FRIENDLY_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.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -19,7 +13,6 @@ 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
@ -47,12 +40,6 @@ 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:
@ -64,7 +51,7 @@ 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 _attr_device_class = DEVICE_CLASS_DATE
def __init__(self, coordinator: DataUpdateCoordinator, entry: ConfigEntry) -> None: def __init__(self, coordinator: DataUpdateCoordinator, entry: ConfigEntry) -> None:
"""Initialize the sensor.""" """Initialize the sensor."""
@ -103,9 +90,7 @@ 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: async_get_utc_midnight( ATTR_NEXT_PICKUP_DATE: next_pickup_event.date.isoformat(),
next_pickup_event.date
).isoformat(),
} }
) )
self._attr_native_value = async_get_utc_midnight(pickup_event.date).isoformat() self._attr_native_value = pickup_event.date.isoformat()