mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Move imports to top for modbus (#29515)
* Move imports to top for modbus * Include imports for TCP and UDP ModbusClients
This commit is contained in:
parent
8def0326dd
commit
fcf18aca34
@ -2,6 +2,8 @@
|
|||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from pymodbus.client.sync import ModbusSerialClient, ModbusTcpClient, ModbusUdpClient
|
||||||
|
from pymodbus.transaction import ModbusRtuFramer
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -91,9 +93,7 @@ def setup_client(client_config):
|
|||||||
client_type = client_config[CONF_TYPE]
|
client_type = client_config[CONF_TYPE]
|
||||||
|
|
||||||
if client_type == "serial":
|
if client_type == "serial":
|
||||||
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
|
return ModbusSerialClient(
|
||||||
|
|
||||||
return ModbusClient(
|
|
||||||
method=client_config[CONF_METHOD],
|
method=client_config[CONF_METHOD],
|
||||||
port=client_config[CONF_PORT],
|
port=client_config[CONF_PORT],
|
||||||
baudrate=client_config[CONF_BAUDRATE],
|
baudrate=client_config[CONF_BAUDRATE],
|
||||||
@ -103,27 +103,20 @@ def setup_client(client_config):
|
|||||||
timeout=client_config[CONF_TIMEOUT],
|
timeout=client_config[CONF_TIMEOUT],
|
||||||
)
|
)
|
||||||
if client_type == "rtuovertcp":
|
if client_type == "rtuovertcp":
|
||||||
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
|
return ModbusTcpClient(
|
||||||
from pymodbus.transaction import ModbusRtuFramer
|
|
||||||
|
|
||||||
return ModbusClient(
|
|
||||||
host=client_config[CONF_HOST],
|
host=client_config[CONF_HOST],
|
||||||
port=client_config[CONF_PORT],
|
port=client_config[CONF_PORT],
|
||||||
framer=ModbusRtuFramer,
|
framer=ModbusRtuFramer,
|
||||||
timeout=client_config[CONF_TIMEOUT],
|
timeout=client_config[CONF_TIMEOUT],
|
||||||
)
|
)
|
||||||
if client_type == "tcp":
|
if client_type == "tcp":
|
||||||
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
|
return ModbusTcpClient(
|
||||||
|
|
||||||
return ModbusClient(
|
|
||||||
host=client_config[CONF_HOST],
|
host=client_config[CONF_HOST],
|
||||||
port=client_config[CONF_PORT],
|
port=client_config[CONF_PORT],
|
||||||
timeout=client_config[CONF_TIMEOUT],
|
timeout=client_config[CONF_TIMEOUT],
|
||||||
)
|
)
|
||||||
if client_type == "udp":
|
if client_type == "udp":
|
||||||
from pymodbus.client.sync import ModbusUdpClient as ModbusClient
|
return ModbusUdpClient(
|
||||||
|
|
||||||
return ModbusClient(
|
|
||||||
host=client_config[CONF_HOST],
|
host=client_config[CONF_HOST],
|
||||||
port=client_config[CONF_PORT],
|
port=client_config[CONF_PORT],
|
||||||
timeout=client_config[CONF_TIMEOUT],
|
timeout=client_config[CONF_TIMEOUT],
|
||||||
|
@ -6,8 +6,8 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice
|
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
|
||||||
HVAC_MODE_AUTO,
|
HVAC_MODE_AUTO,
|
||||||
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"""Support for Modbus Register sensors."""
|
"""Support for Modbus Register sensors."""
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
|
Loading…
x
Reference in New Issue
Block a user