[ci skip] home assistant integration
This commit is contained in:
54
custom_components/victron_mk2_mqtt/number.py
Normal file
54
custom_components/victron_mk2_mqtt/number.py
Normal file
@@ -0,0 +1,54 @@
|
||||
"""Number entities for Victron MK2 MQTT integration."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
|
||||
from homeassistant.const import UnitOfElectricCurrent
|
||||
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 number entities."""
|
||||
bridge: VictronMqttBridge = hass.data[DOMAIN][DATA_BRIDGE]
|
||||
async_add_entities([VictronRemotePanelCurrentLimitNumber(bridge)])
|
||||
|
||||
|
||||
class VictronRemotePanelCurrentLimitNumber(VictronMqttEntity, NumberEntity):
|
||||
"""Remote panel AC input current limit."""
|
||||
|
||||
_attr_name = "Remote Panel Current Limit"
|
||||
_attr_icon = "mdi:current-ac"
|
||||
_attr_native_min_value = 0.0
|
||||
_attr_native_max_value = 100.0
|
||||
_attr_native_step = 0.1
|
||||
_attr_mode = NumberMode.BOX
|
||||
_attr_device_class = NumberDeviceClass.CURRENT
|
||||
_attr_native_unit_of_measurement = UnitOfElectricCurrent.AMPERE
|
||||
|
||||
def __init__(self, bridge: VictronMqttBridge) -> None:
|
||||
super().__init__(bridge)
|
||||
self._attr_unique_id = f"{bridge.topic_root}_remote_panel_current_limit"
|
||||
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
return self.bridge.current_limit
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
return bool(self.bridge.command_topic)
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
await self.bridge.async_publish_command(
|
||||
{"kind": "panel_state", "current_limit": float(value)}
|
||||
)
|
||||
Reference in New Issue
Block a user