mirror of
https://github.com/home-assistant/core.git
synced 2026-09-09 15:11:40 +01:00
26 lines
831 B
Python
26 lines
831 B
Python
"""Helpers for the SolarEdge Modbus integration."""
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
from modbus_connection import ModbusSerialParams, ModbusTcpParams
|
|
|
|
from homeassistant.const import CONF_DEVICE, CONF_HOST, CONF_PORT, CONF_TYPE
|
|
|
|
from .const import CONF_BAUDRATE, TYPE_SERIAL
|
|
|
|
|
|
def create_modbus_params(
|
|
data: Mapping[str, Any],
|
|
) -> ModbusSerialParams | ModbusTcpParams:
|
|
"""Build the Modbus link parameters from config entry data.
|
|
|
|
The library's serial defaults are 8N1, which is what SolarEdge's RS485
|
|
ports speak; only the baud rate is worth asking for.
|
|
"""
|
|
if data[CONF_TYPE] == TYPE_SERIAL:
|
|
return ModbusSerialParams(
|
|
device=data[CONF_DEVICE], baudrate=data[CONF_BAUDRATE]
|
|
)
|
|
return ModbusTcpParams(host=data[CONF_HOST], port=data[CONF_PORT])
|