mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Implement sync time button for moehlenhoff_alpha2 (#85676)
* Implement sync time button for moehlenhoff_alpha2 * fix outdated doc comment Co-authored-by: j-a-n <oss@janschneider.net> * address review comments Co-authored-by: j-a-n <oss@janschneider.net>
This commit is contained in:
parent
cb04a52220
commit
49031b8fa7
@ -17,7 +17,7 @@ from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR, Platform.BINARY_SENSOR]
|
||||
PLATFORMS = [Platform.BUTTON, Platform.CLIMATE, Platform.SENSOR, Platform.BINARY_SENSOR]
|
||||
|
||||
UPDATE_INTERVAL = timedelta(seconds=60)
|
||||
|
||||
|
41
homeassistant/components/moehlenhoff_alpha2/button.py
Normal file
41
homeassistant/components/moehlenhoff_alpha2/button.py
Normal file
@ -0,0 +1,41 @@
|
||||
"""Button entity to set the time of the Alpha2 base."""
|
||||
|
||||
from homeassistant.components.button import ButtonEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util import dt
|
||||
|
||||
from . import Alpha2BaseCoordinator
|
||||
from .const import DOMAIN
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Add Alpha2 button entities."""
|
||||
|
||||
coordinator: Alpha2BaseCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
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.now())
|
Loading…
x
Reference in New Issue
Block a user