47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Select entities for Victron MK2 MQTT integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from homeassistant.components.select import SelectEntity
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .const import DATA_BRIDGE, DOMAIN, PANEL_MODES
|
|
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 select entities."""
|
|
bridge: VictronMqttBridge = hass.data[DOMAIN][DATA_BRIDGE]
|
|
async_add_entities([VictronRemotePanelModeSelect(bridge)])
|
|
|
|
|
|
class VictronRemotePanelModeSelect(VictronMqttEntity, SelectEntity):
|
|
"""Remote panel mode select."""
|
|
|
|
_attr_name = "Remote Panel Mode"
|
|
_attr_options = list(PANEL_MODES)
|
|
_attr_icon = "mdi:transmission-tower-export"
|
|
|
|
def __init__(self, bridge: VictronMqttBridge) -> None:
|
|
super().__init__(bridge)
|
|
self._attr_unique_id = f"{bridge.topic_root}_remote_panel_mode"
|
|
|
|
@property
|
|
def current_option(self) -> str | None:
|
|
return self.bridge.panel_mode
|
|
|
|
@property
|
|
def available(self) -> bool:
|
|
return bool(self.bridge.command_topic)
|
|
|
|
async def async_select_option(self, option: str) -> None:
|
|
await self.bridge.async_publish_command({"kind": "panel_state", "switch": option})
|