1 """Component to allow setting time as platforms."""
3 from __future__
import annotations
5 from datetime
import time, 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[TimeEntity]] =
HassKey(DOMAIN)
26 ENTITY_ID_FORMAT = DOMAIN +
".{}"
27 PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA
28 PLATFORM_SCHEMA_BASE = cv.PLATFORM_SCHEMA_BASE
32 __all__ = [
"DOMAIN",
"TimeEntity",
"TimeEntityDescription"]
36 """Service call wrapper to set a new date."""
37 return await entity.async_set_value(service_call.data[ATTR_TIME])
40 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
41 """Set up Time entities."""
42 component = hass.data[DATA_COMPONENT] = EntityComponent[TimeEntity](
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_TIME): cv.time}, _async_set_value
55 """Set up a config entry."""
60 """Unload a config entry."""
65 """A class that describes time entities."""
68 CACHED_PROPERTIES_WITH_ATTR_ = {
"native_value"}
72 """Representation of a Time entity."""
74 entity_description: TimeEntityDescription
75 _attr_native_value: time |
None
76 _attr_device_class:
None =
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 time."""
102 return self._attr_native_value
105 """Change the time."""
106 raise NotImplementedError
109 """Change the time."""
110 await self.
hasshass.async_add_executor_job(self.
set_valueset_value, value)
None set_value(self, time value)
None state_attributes(self)
None async_set_value(self, time value)
time|None native_value(self)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None _async_set_value(TimeEntity entity, ServiceCall service_call)
bool async_setup(HomeAssistant hass, ConfigType config)