[ci skip] home assistant integration
This commit is contained in:
48
custom_components/victron_mk2_mqtt/switch.py
Normal file
48
custom_components/victron_mk2_mqtt/switch.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Switch entities for Victron MK2 MQTT integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DATA_BRIDGE, DOMAIN
|
||||
from .coordinator import VictronMqttBridge
|
||||
from .entity import VictronMqttEntity
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: dict[str, Any],
|
||||
async_add_entities,
|
||||
discovery_info: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""Set up Victron switch entities."""
|
||||
bridge: VictronMqttBridge = hass.data[DOMAIN][DATA_BRIDGE]
|
||||
async_add_entities([VictronRemotePanelStandbySwitch(bridge)])
|
||||
|
||||
|
||||
class VictronRemotePanelStandbySwitch(VictronMqttEntity, SwitchEntity):
|
||||
"""Remote panel standby switch."""
|
||||
|
||||
_attr_name = "Remote Panel Standby"
|
||||
_attr_icon = "mdi:power-sleep"
|
||||
|
||||
def __init__(self, bridge: VictronMqttBridge) -> None:
|
||||
super().__init__(bridge)
|
||||
self._attr_unique_id = f"{bridge.topic_root}_remote_panel_standby"
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
return bool(self.bridge.standby)
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
return bool(self.bridge.command_topic)
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
await self.bridge.async_publish_command({"kind": "standby", "standby": True})
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
await self.bridge.async_publish_command({"kind": "standby", "standby": False})
|
||||
Reference in New Issue
Block a user