1 """Component to allow setting date as platforms."""
3 from __future__
import annotations
5 from datetime
import date, timedelta
7 from typing
import final
9 from propcache
import cached_property
10 import voluptuous
as vol
21 from .const
import DOMAIN, SERVICE_SET_VALUE
23 _LOGGER = logging.getLogger(__name__)
25 DATA_COMPONENT: HassKey[EntityComponent[DateEntity]] =
HassKey(DOMAIN)
26 ENTITY_ID_FORMAT = DOMAIN +
".{}"
27 PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
28 PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
32 __all__ = [
"DOMAIN",
"DateEntity",
"DateEntityDescription"]
36 """Service call wrapper to set a new date."""
37 return await entity.async_set_value(service_call.data[ATTR_DATE])
40 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
41 """Set up Date entities."""
42 component = hass.data[DATA_COMPONENT] = EntityComponent[DateEntity](
43 _LOGGER, DOMAIN, hass, SCAN_INTERVAL
45 await component.async_setup(config)
47 component.async_register_entity_service(
48 SERVICE_SET_VALUE, {vol.Required(ATTR_DATE): cv.date}, _async_set_value
55 """Set up a config entry."""
60 """Unload a config entry."""
65 """A class that describes date entities."""
68 CACHED_PROPERTIES_WITH_ATTR_ = {
"native_value"}
72 """Representation of a Date entity."""
74 entity_description: DateEntityDescription
75 _attr_device_class:
None
76 _attr_native_value: date |
None
77 _attr_state:
None =
None
82 """Return the device class for the entity."""
88 """Return the state attributes."""
94 """Return the entity state."""
101 """Return the value reported by the date."""
102 return self._attr_native_value
105 """Change the date."""
106 raise NotImplementedError
109 """Change the date."""
110 await self.
hasshass.async_add_executor_job(self.
set_valueset_value, value)
date|None native_value(self)
None set_value(self, date value)
None async_set_value(self, date value)
None state_attributes(self)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup(HomeAssistant hass, ConfigType config)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
None _async_set_value(DateEntity entity, ServiceCall service_call)