1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-09 00:47:04 +01:00

ElkM1 integration: Add time entity for settings (#170035)

This commit is contained in:
Glenn Waters
2026-05-07 14:17:42 -04:00
committed by GitHub
parent 946a3bcf11
commit c406e1aeed
2 changed files with 67 additions and 0 deletions
@@ -76,6 +76,7 @@ PLATFORMS = [
Platform.SCENE,
Platform.SENSOR,
Platform.SWITCH,
Platform.TIME,
]
+66
View File
@@ -0,0 +1,66 @@
"""Support for ElkM1 time entities."""
from datetime import time as dt_time
import logging
from typing import Any, cast
from elkm1_lib.const import SettingFormat
from elkm1_lib.elements import Element
from elkm1_lib.settings import Setting
from homeassistant.components.time import TimeEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import ElkM1ConfigEntry
from .entity import ElkAttachedEntity, ElkEntity, create_elk_entities
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ElkM1ConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the Elk-M1 time platform."""
elk_data = config_entry.runtime_data
elk = elk_data.elk
entities: list[ElkEntity] = []
time_settings = [
setting
for setting in cast(list[Setting], elk.settings)
if setting.value_format == SettingFormat.TIME_OF_DAY
]
create_elk_entities(
elk_data,
time_settings,
"setting",
ElkTimeSetting,
entities,
)
async_add_entities(entities)
class ElkTimeSetting(ElkAttachedEntity, TimeEntity):
"""Representation of an Elk-M1 Time Setting."""
_element: Setting
def _element_changed(self, element: Element, changeset: dict[str, Any]) -> None:
value = self._element.value
# Guard against the panel possibly changing the underlying
# type without us knowing about the change
if isinstance(value, tuple):
self._attr_native_value = dt_time(hour=value[0], minute=value[1])
else:
self._attr_available = False
_LOGGER.warning(
"Setting type for '%s' differs between the ElkM1 and the entity. Restart the integration to fix",
self.entity_id,
)
async def async_set_value(self, value: dt_time) -> None:
"""Set the time of the setting."""
self._element.set((value.hour, value.minute))