mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Correct modbus serial method parameter (#89738)
This commit is contained in:
parent
52981699cf
commit
90a4afb6fa
@ -16,7 +16,7 @@ from pymodbus.client import (
|
|||||||
from pymodbus.constants import Defaults
|
from pymodbus.constants import Defaults
|
||||||
from pymodbus.exceptions import ModbusException
|
from pymodbus.exceptions import ModbusException
|
||||||
from pymodbus.pdu import ModbusResponse
|
from pymodbus.pdu import ModbusResponse
|
||||||
from pymodbus.transaction import ModbusRtuFramer
|
from pymodbus.transaction import ModbusAsciiFramer, ModbusRtuFramer, ModbusSocketFramer
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -281,9 +281,12 @@ class ModbusHub:
|
|||||||
}
|
}
|
||||||
if self._config_type == SERIAL:
|
if self._config_type == SERIAL:
|
||||||
# serial configuration
|
# serial configuration
|
||||||
|
if client_config[CONF_METHOD] == "ascii":
|
||||||
|
self._pb_params["framer"] = ModbusAsciiFramer
|
||||||
|
else:
|
||||||
|
self._pb_params["framer"] = ModbusRtuFramer
|
||||||
self._pb_params.update(
|
self._pb_params.update(
|
||||||
{
|
{
|
||||||
"method": client_config[CONF_METHOD],
|
|
||||||
"baudrate": client_config[CONF_BAUDRATE],
|
"baudrate": client_config[CONF_BAUDRATE],
|
||||||
"stopbits": client_config[CONF_STOPBITS],
|
"stopbits": client_config[CONF_STOPBITS],
|
||||||
"bytesize": client_config[CONF_BYTESIZE],
|
"bytesize": client_config[CONF_BYTESIZE],
|
||||||
@ -295,6 +298,8 @@ class ModbusHub:
|
|||||||
self._pb_params["host"] = client_config[CONF_HOST]
|
self._pb_params["host"] = client_config[CONF_HOST]
|
||||||
if self._config_type == RTUOVERTCP:
|
if self._config_type == RTUOVERTCP:
|
||||||
self._pb_params["framer"] = ModbusRtuFramer
|
self._pb_params["framer"] = ModbusRtuFramer
|
||||||
|
else:
|
||||||
|
self._pb_params["framer"] = ModbusSocketFramer
|
||||||
|
|
||||||
Defaults.Timeout = client_config[CONF_TIMEOUT]
|
Defaults.Timeout = client_config[CONF_TIMEOUT]
|
||||||
if CONF_MSG_WAIT in client_config:
|
if CONF_MSG_WAIT in client_config:
|
||||||
|
@ -378,7 +378,7 @@ async def test_duplicate_entity_validator(do_config) -> None:
|
|||||||
CONF_TYPE: SERIAL,
|
CONF_TYPE: SERIAL,
|
||||||
CONF_BAUDRATE: 9600,
|
CONF_BAUDRATE: 9600,
|
||||||
CONF_BYTESIZE: 8,
|
CONF_BYTESIZE: 8,
|
||||||
CONF_METHOD: "rtu",
|
CONF_METHOD: "ascii",
|
||||||
CONF_PORT: TEST_PORT_SERIAL,
|
CONF_PORT: TEST_PORT_SERIAL,
|
||||||
CONF_PARITY: "E",
|
CONF_PARITY: "E",
|
||||||
CONF_STOPBITS: 1,
|
CONF_STOPBITS: 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user