All checks were successful
continuous-integration/drone/push Build is passing
77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
"""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]
|
|
entities: list[SwitchEntity] = [VictronRemotePanelStandbySwitch(bridge)]
|
|
if bridge.venus_guide_compat:
|
|
entities.append(VictronESSOptimizedModeSwitch(bridge))
|
|
async_add_entities(entities)
|
|
|
|
|
|
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})
|
|
|
|
|
|
class VictronESSOptimizedModeSwitch(VictronMqttEntity, SwitchEntity):
|
|
"""Guide-compatible ESS optimized mode switch."""
|
|
|
|
_attr_name = "ESS Optimized Mode"
|
|
_attr_icon = "mdi:battery-sync"
|
|
|
|
def __init__(self, bridge: VictronMqttBridge) -> None:
|
|
super().__init__(bridge)
|
|
self._attr_unique_id = f"{bridge.topic_root}_ess_optimized_mode"
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return self.bridge.ess_mode == 10
|
|
|
|
@property
|
|
def available(self) -> bool:
|
|
return bool(self.bridge.command_topic and self.bridge.venus_guide_compat)
|
|
|
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
|
await self.bridge.async_publish_command({"kind": "ess_mode", "value": 10})
|
|
|
|
async def async_turn_off(self, **kwargs: Any) -> None:
|
|
await self.bridge.async_publish_command({"kind": "ess_mode", "value": 9})
|