41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""Switch platform for Sternwarte."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.switch import SwitchEntity
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from .const import DOMAIN, ENTITY_ROOF_POWER
|
|
from .entity import SternwarteEntity
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: ConfigEntry,
|
|
async_add_entities: AddEntitiesCallback,
|
|
) -> None:
|
|
"""Set up Sternwarte switches."""
|
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
|
async_add_entities([SternwarteRoofPowerSwitch(coordinator)])
|
|
|
|
|
|
class SternwarteRoofPowerSwitch(SternwarteEntity, SwitchEntity):
|
|
"""Roof power switch."""
|
|
|
|
_attr_name = "Dachsteuerung"
|
|
|
|
def __init__(self, coordinator):
|
|
super().__init__(coordinator, ENTITY_ROOF_POWER)
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return self.coordinator.data.roof_power
|
|
|
|
async def async_turn_on(self, **kwargs) -> None:
|
|
await self.coordinator.async_turn_power_on()
|
|
|
|
async def async_turn_off(self, **kwargs) -> None:
|
|
await self.coordinator.async_turn_power_off()
|