mirror of
https://github.com/home-assistant/core.git
synced 2026-04-19 08:19:26 +01:00
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""Button entity to set the time of the Alpha2 base."""
|
|
|
|
from homeassistant.components.button import ButtonEntity
|
|
from homeassistant.const import EntityCategory
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
from homeassistant.util import dt as dt_util
|
|
|
|
from .coordinator import Alpha2BaseCoordinator, Alpha2ConfigEntry
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
config_entry: Alpha2ConfigEntry,
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
|
) -> None:
|
|
"""Add Alpha2 button entities."""
|
|
|
|
coordinator = config_entry.runtime_data
|
|
|
|
async_add_entities([Alpha2TimeSyncButton(coordinator, config_entry.entry_id)])
|
|
|
|
|
|
class Alpha2TimeSyncButton(CoordinatorEntity[Alpha2BaseCoordinator], ButtonEntity):
|
|
"""Alpha2 virtual time sync button."""
|
|
|
|
_attr_name = "Sync time"
|
|
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
|
|
|
def __init__(self, coordinator: Alpha2BaseCoordinator, entry_id: str) -> None:
|
|
"""Initialize Alpha2TimeSyncButton."""
|
|
super().__init__(coordinator)
|
|
|
|
self._attr_unique_id = f"{entry_id}:sync_time"
|
|
|
|
async def async_press(self) -> None:
|
|
"""Synchronize current local time from HA instance to base station."""
|
|
await self.coordinator.base.set_datetime(dt_util.now())
|