mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
[modbus_controller] Fix linting and formatting issues (#7441)
This commit is contained in:
parent
3835ad8c1f
commit
73e469ae52
8 changed files with 54 additions and 59 deletions
|
@ -1,27 +1,29 @@
|
||||||
import binascii
|
import binascii
|
||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome import automation
|
from esphome import automation
|
||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import modbus
|
from esphome.components import modbus
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ADDRESS,
|
CONF_ADDRESS,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
CONF_NAME,
|
|
||||||
CONF_LAMBDA,
|
CONF_LAMBDA,
|
||||||
|
CONF_NAME,
|
||||||
CONF_OFFSET,
|
CONF_OFFSET,
|
||||||
CONF_TRIGGER_ID,
|
CONF_TRIGGER_ID,
|
||||||
)
|
)
|
||||||
from esphome.cpp_helpers import logging
|
from esphome.cpp_helpers import logging
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_ALLOW_DUPLICATE_COMMANDS,
|
CONF_ALLOW_DUPLICATE_COMMANDS,
|
||||||
CONF_BITMASK,
|
CONF_BITMASK,
|
||||||
CONF_BYTE_OFFSET,
|
CONF_BYTE_OFFSET,
|
||||||
CONF_COMMAND_THROTTLE,
|
CONF_COMMAND_THROTTLE,
|
||||||
CONF_OFFLINE_SKIP_UPDATES,
|
|
||||||
CONF_CUSTOM_COMMAND,
|
CONF_CUSTOM_COMMAND,
|
||||||
CONF_FORCE_NEW_RANGE,
|
CONF_FORCE_NEW_RANGE,
|
||||||
CONF_MODBUS_CONTROLLER_ID,
|
|
||||||
CONF_MAX_CMD_RETRIES,
|
CONF_MAX_CMD_RETRIES,
|
||||||
|
CONF_MODBUS_CONTROLLER_ID,
|
||||||
|
CONF_OFFLINE_SKIP_UPDATES,
|
||||||
CONF_ON_COMMAND_SENT,
|
CONF_ON_COMMAND_SENT,
|
||||||
CONF_REGISTER_COUNT,
|
CONF_REGISTER_COUNT,
|
||||||
CONF_REGISTER_TYPE,
|
CONF_REGISTER_TYPE,
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import binary_sensor
|
from esphome.components import binary_sensor
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.codegen as cg
|
|
||||||
|
|
||||||
from esphome.const import CONF_ADDRESS, CONF_ID
|
from esphome.const import CONF_ADDRESS, CONF_ID
|
||||||
|
|
||||||
from .. import (
|
from .. import (
|
||||||
add_modbus_base_properties,
|
MODBUS_REGISTER_TYPE,
|
||||||
modbus_controller_ns,
|
|
||||||
modbus_calc_properties,
|
|
||||||
validate_modbus_register,
|
|
||||||
ModbusItemBaseSchema,
|
ModbusItemBaseSchema,
|
||||||
SensorItem,
|
SensorItem,
|
||||||
MODBUS_REGISTER_TYPE,
|
add_modbus_base_properties,
|
||||||
|
modbus_calc_properties,
|
||||||
|
modbus_controller_ns,
|
||||||
|
validate_modbus_register,
|
||||||
)
|
)
|
||||||
from ..const import (
|
from ..const import (
|
||||||
CONF_BITMASK,
|
CONF_BITMASK,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome.components import number
|
from esphome.components import number
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.const import (
|
from esphome.const import (
|
||||||
CONF_ADDRESS,
|
CONF_ADDRESS,
|
||||||
CONF_ID,
|
CONF_ID,
|
||||||
|
@ -12,14 +12,13 @@ from esphome.const import (
|
||||||
|
|
||||||
from .. import (
|
from .. import (
|
||||||
MODBUS_WRITE_REGISTER_TYPE,
|
MODBUS_WRITE_REGISTER_TYPE,
|
||||||
add_modbus_base_properties,
|
SENSOR_VALUE_TYPE,
|
||||||
modbus_controller_ns,
|
|
||||||
modbus_calc_properties,
|
|
||||||
ModbusItemBaseSchema,
|
ModbusItemBaseSchema,
|
||||||
SensorItem,
|
SensorItem,
|
||||||
SENSOR_VALUE_TYPE,
|
add_modbus_base_properties,
|
||||||
|
modbus_calc_properties,
|
||||||
|
modbus_controller_ns,
|
||||||
)
|
)
|
||||||
|
|
||||||
from ..const import (
|
from ..const import (
|
||||||
CONF_BITMASK,
|
CONF_BITMASK,
|
||||||
CONF_CUSTOM_COMMAND,
|
CONF_CUSTOM_COMMAND,
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome.components import output
|
from esphome.components import output
|
||||||
from esphome.const import (
|
import esphome.config_validation as cv
|
||||||
CONF_ADDRESS,
|
from esphome.const import CONF_ADDRESS, CONF_ID, CONF_MULTIPLY
|
||||||
CONF_ID,
|
|
||||||
CONF_MULTIPLY,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .. import (
|
from .. import (
|
||||||
modbus_controller_ns,
|
SENSOR_VALUE_TYPE,
|
||||||
modbus_calc_properties,
|
|
||||||
ModbusItemBaseSchema,
|
ModbusItemBaseSchema,
|
||||||
SensorItem,
|
SensorItem,
|
||||||
SENSOR_VALUE_TYPE,
|
modbus_calc_properties,
|
||||||
|
modbus_controller_ns,
|
||||||
)
|
)
|
||||||
|
|
||||||
from ..const import (
|
from ..const import (
|
||||||
CONF_MODBUS_CONTROLLER_ID,
|
CONF_MODBUS_CONTROLLER_ID,
|
||||||
CONF_REGISTER_TYPE,
|
CONF_REGISTER_TYPE,
|
||||||
|
@ -65,6 +60,7 @@ CONFIG_SCHEMA = cv.typed_schema(
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
byte_offset, reg_count = modbus_calc_properties(config)
|
byte_offset, reg_count = modbus_calc_properties(config)
|
||||||
# Binary Output
|
# Binary Output
|
||||||
|
write_template = None
|
||||||
if config[CONF_REGISTER_TYPE] == "coil":
|
if config[CONF_REGISTER_TYPE] == "coil":
|
||||||
var = cg.new_Pvariable(
|
var = cg.new_Pvariable(
|
||||||
config[CONF_ID],
|
config[CONF_ID],
|
||||||
|
@ -72,7 +68,7 @@ async def to_code(config):
|
||||||
byte_offset,
|
byte_offset,
|
||||||
)
|
)
|
||||||
if CONF_WRITE_LAMBDA in config:
|
if CONF_WRITE_LAMBDA in config:
|
||||||
template_ = await cg.process_lambda(
|
write_template = await cg.process_lambda(
|
||||||
config[CONF_WRITE_LAMBDA],
|
config[CONF_WRITE_LAMBDA],
|
||||||
[
|
[
|
||||||
(ModbusBinaryOutput.operator("ptr"), "item"),
|
(ModbusBinaryOutput.operator("ptr"), "item"),
|
||||||
|
@ -92,7 +88,7 @@ async def to_code(config):
|
||||||
)
|
)
|
||||||
cg.add(var.set_write_multiply(config[CONF_MULTIPLY]))
|
cg.add(var.set_write_multiply(config[CONF_MULTIPLY]))
|
||||||
if CONF_WRITE_LAMBDA in config:
|
if CONF_WRITE_LAMBDA in config:
|
||||||
template_ = await cg.process_lambda(
|
write_template = await cg.process_lambda(
|
||||||
config[CONF_WRITE_LAMBDA],
|
config[CONF_WRITE_LAMBDA],
|
||||||
[
|
[
|
||||||
(ModbusFloatOutput.operator("ptr"), "item"),
|
(ModbusFloatOutput.operator("ptr"), "item"),
|
||||||
|
@ -105,5 +101,5 @@ async def to_code(config):
|
||||||
parent = await cg.get_variable(config[CONF_MODBUS_CONTROLLER_ID])
|
parent = await cg.get_variable(config[CONF_MODBUS_CONTROLLER_ID])
|
||||||
cg.add(var.set_use_write_mutiple(config[CONF_USE_WRITE_MULTIPLE]))
|
cg.add(var.set_use_write_mutiple(config[CONF_USE_WRITE_MULTIPLE]))
|
||||||
cg.add(var.set_parent(parent))
|
cg.add(var.set_parent(parent))
|
||||||
if CONF_WRITE_LAMBDA in config:
|
if write_template:
|
||||||
cg.add(var.set_write_template(template_))
|
cg.add(var.set_write_template(write_template))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome.components import select
|
from esphome.components import select
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome.const import CONF_ADDRESS, CONF_ID, CONF_LAMBDA, CONF_OPTIMISTIC
|
from esphome.const import CONF_ADDRESS, CONF_ID, CONF_LAMBDA, CONF_OPTIMISTIC
|
||||||
|
|
||||||
from .. import (
|
from .. import (
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import sensor
|
from esphome.components import sensor
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.codegen as cg
|
from esphome.const import CONF_ADDRESS, CONF_ID
|
||||||
|
|
||||||
from esphome.const import CONF_ID, CONF_ADDRESS
|
|
||||||
from .. import (
|
from .. import (
|
||||||
add_modbus_base_properties,
|
|
||||||
modbus_controller_ns,
|
|
||||||
modbus_calc_properties,
|
|
||||||
validate_modbus_register,
|
|
||||||
ModbusItemBaseSchema,
|
|
||||||
SensorItem,
|
|
||||||
MODBUS_REGISTER_TYPE,
|
MODBUS_REGISTER_TYPE,
|
||||||
SENSOR_VALUE_TYPE,
|
SENSOR_VALUE_TYPE,
|
||||||
|
ModbusItemBaseSchema,
|
||||||
|
SensorItem,
|
||||||
|
add_modbus_base_properties,
|
||||||
|
modbus_calc_properties,
|
||||||
|
modbus_controller_ns,
|
||||||
|
validate_modbus_register,
|
||||||
)
|
)
|
||||||
from ..const import (
|
from ..const import (
|
||||||
CONF_BITMASK,
|
CONF_BITMASK,
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import switch
|
from esphome.components import switch
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.codegen as cg
|
from esphome.const import CONF_ADDRESS, CONF_ID
|
||||||
|
|
||||||
|
|
||||||
from esphome.const import CONF_ID, CONF_ADDRESS
|
|
||||||
from .. import (
|
from .. import (
|
||||||
add_modbus_base_properties,
|
MODBUS_REGISTER_TYPE,
|
||||||
modbus_controller_ns,
|
|
||||||
modbus_calc_properties,
|
|
||||||
validate_modbus_register,
|
|
||||||
ModbusItemBaseSchema,
|
ModbusItemBaseSchema,
|
||||||
SensorItem,
|
SensorItem,
|
||||||
MODBUS_REGISTER_TYPE,
|
add_modbus_base_properties,
|
||||||
|
modbus_calc_properties,
|
||||||
|
modbus_controller_ns,
|
||||||
|
validate_modbus_register,
|
||||||
)
|
)
|
||||||
from ..const import (
|
from ..const import (
|
||||||
CONF_BITMASK,
|
CONF_BITMASK,
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import text_sensor
|
from esphome.components import text_sensor
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.codegen as cg
|
|
||||||
|
|
||||||
|
|
||||||
from esphome.const import CONF_ADDRESS, CONF_ID
|
from esphome.const import CONF_ADDRESS, CONF_ID
|
||||||
|
|
||||||
from .. import (
|
from .. import (
|
||||||
add_modbus_base_properties,
|
MODBUS_REGISTER_TYPE,
|
||||||
modbus_controller_ns,
|
|
||||||
modbus_calc_properties,
|
|
||||||
validate_modbus_register,
|
|
||||||
ModbusItemBaseSchema,
|
ModbusItemBaseSchema,
|
||||||
SensorItem,
|
SensorItem,
|
||||||
MODBUS_REGISTER_TYPE,
|
add_modbus_base_properties,
|
||||||
|
modbus_calc_properties,
|
||||||
|
modbus_controller_ns,
|
||||||
|
validate_modbus_register,
|
||||||
)
|
)
|
||||||
from ..const import (
|
from ..const import (
|
||||||
CONF_FORCE_NEW_RANGE,
|
CONF_FORCE_NEW_RANGE,
|
||||||
CONF_MODBUS_CONTROLLER_ID,
|
CONF_MODBUS_CONTROLLER_ID,
|
||||||
|
CONF_RAW_ENCODE,
|
||||||
CONF_REGISTER_COUNT,
|
CONF_REGISTER_COUNT,
|
||||||
|
CONF_REGISTER_TYPE,
|
||||||
CONF_RESPONSE_SIZE,
|
CONF_RESPONSE_SIZE,
|
||||||
CONF_SKIP_UPDATES,
|
CONF_SKIP_UPDATES,
|
||||||
CONF_RAW_ENCODE,
|
|
||||||
CONF_REGISTER_TYPE,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
DEPENDENCIES = ["modbus_controller"]
|
DEPENDENCIES = ["modbus_controller"]
|
||||||
|
|
Loading…
Reference in a new issue