1 """Support for KNX/IP time."""
3 from __future__
import annotations
5 from datetime
import time
as dt_time
8 from xknx.devices
import TimeDevice
as XknxTimeDevice
9 from xknx.dpt.dpt_10
import KNXTime
as XknxTime
11 from homeassistant
import config_entries
25 from .
import KNXModule
33 from .entity
import KnxYamlEntity
39 async_add_entities: AddEntitiesCallback,
41 """Set up entities for KNX platform."""
42 knx_module = hass.data[KNX_MODULE_KEY]
43 config: list[ConfigType] = knx_module.config_yaml[Platform.TIME]
46 KNXTimeEntity(knx_module, entity_config)
for entity_config
in config
51 """Return a XKNX DateTime object to be used within XKNX."""
52 return XknxTimeDevice(
54 name=config[CONF_NAME],
56 group_address=config[KNX_ADDRESS],
57 group_address_state=config.get(CONF_STATE_ADDRESS),
58 respond_to_read=config[CONF_RESPOND_TO_READ],
59 sync_state=config[CONF_SYNC_STATE],
64 """Representation of a KNX time."""
66 _device: XknxTimeDevice
68 def __init__(self, knx_module: KNXModule, config: ConfigType) ->
None:
69 """Initialize a KNX time."""
71 knx_module=knx_module,
78 """Restore last state."""
81 not self.
_device_device.remote_value.readable
83 and last_state.state
not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
85 self.
_device_device.remote_value.value = XknxTime.from_time(
86 dt_time.fromisoformat(last_state.state)
91 """Return the latest value."""
92 return self.
_device_device.value
95 """Change the value."""
96 await self.
_device_device.set(value)
None async_set_value(self, dt_time value)
None __init__(self, KNXModule knx_module, ConfigType config)
None async_added_to_hass(self)
dt_time|None native_value(self)
State|None async_get_last_state(self)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
XknxTimeDevice _create_xknx_device(XKNX xknx, ConfigType config)