COnvert DATA_TYPE to enum. (#57699)
parent
faf5c2eb40
commit
4417ffb407
|
@ -96,20 +96,6 @@ from .const import (
|
|||
CONF_TARGET_TEMP,
|
||||
CONF_VERIFY,
|
||||
CONF_WRITE_TYPE,
|
||||
DATA_TYPE_CUSTOM,
|
||||
DATA_TYPE_FLOAT,
|
||||
DATA_TYPE_FLOAT16,
|
||||
DATA_TYPE_FLOAT32,
|
||||
DATA_TYPE_FLOAT64,
|
||||
DATA_TYPE_INT,
|
||||
DATA_TYPE_INT16,
|
||||
DATA_TYPE_INT32,
|
||||
DATA_TYPE_INT64,
|
||||
DATA_TYPE_STRING,
|
||||
DATA_TYPE_UINT,
|
||||
DATA_TYPE_UINT16,
|
||||
DATA_TYPE_UINT32,
|
||||
DATA_TYPE_UINT64,
|
||||
DEFAULT_HUB,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DEFAULT_TEMP_UNIT,
|
||||
|
@ -118,6 +104,7 @@ from .const import (
|
|||
SERIAL,
|
||||
TCP,
|
||||
UDP,
|
||||
DataType,
|
||||
)
|
||||
from .modbus import ModbusHub, async_modbus_setup
|
||||
from .validators import (
|
||||
|
@ -153,23 +140,23 @@ BASE_STRUCT_SCHEMA = BASE_COMPONENT_SCHEMA.extend(
|
|||
]
|
||||
),
|
||||
vol.Optional(CONF_COUNT): cv.positive_int,
|
||||
vol.Optional(CONF_DATA_TYPE, default=DATA_TYPE_INT): vol.In(
|
||||
vol.Optional(CONF_DATA_TYPE, default=DataType.INT): vol.In(
|
||||
[
|
||||
DATA_TYPE_INT16,
|
||||
DATA_TYPE_INT32,
|
||||
DATA_TYPE_INT64,
|
||||
DATA_TYPE_UINT16,
|
||||
DATA_TYPE_UINT32,
|
||||
DATA_TYPE_UINT64,
|
||||
DATA_TYPE_FLOAT16,
|
||||
DATA_TYPE_FLOAT32,
|
||||
DATA_TYPE_FLOAT64,
|
||||
DATA_TYPE_STRING,
|
||||
DATA_TYPE_INT,
|
||||
DATA_TYPE_UINT,
|
||||
DATA_TYPE_FLOAT,
|
||||
DATA_TYPE_STRING,
|
||||
DATA_TYPE_CUSTOM,
|
||||
DataType.INT16,
|
||||
DataType.INT32,
|
||||
DataType.INT64,
|
||||
DataType.UINT16,
|
||||
DataType.UINT32,
|
||||
DataType.UINT64,
|
||||
DataType.FLOAT16,
|
||||
DataType.FLOAT32,
|
||||
DataType.FLOAT64,
|
||||
DataType.STRING,
|
||||
DataType.INT,
|
||||
DataType.UINT,
|
||||
DataType.FLOAT,
|
||||
DataType.STRING,
|
||||
DataType.CUSTOM,
|
||||
]
|
||||
),
|
||||
vol.Optional(CONF_STRUCTURE): cv.string,
|
||||
|
|
|
@ -53,9 +53,9 @@ from .const import (
|
|||
CONF_SWAP_WORD_BYTE,
|
||||
CONF_VERIFY,
|
||||
CONF_WRITE_TYPE,
|
||||
DATA_TYPE_STRING,
|
||||
SIGNAL_START_ENTITY,
|
||||
SIGNAL_STOP_ENTITY,
|
||||
DataType,
|
||||
)
|
||||
from .modbus import ModbusHub
|
||||
|
||||
|
@ -165,7 +165,7 @@ class BaseStructPlatform(BasePlatform, RestoreEntity):
|
|||
|
||||
registers = self._swap_registers(registers)
|
||||
byte_string = b"".join([x.to_bytes(2, byteorder="big") for x in registers])
|
||||
if self._data_type == DATA_TYPE_STRING:
|
||||
if self._data_type == DataType.STRING:
|
||||
return byte_string.decode()
|
||||
|
||||
val = struct.unpack(self._structure, byte_string)
|
||||
|
|
|
@ -34,12 +34,7 @@ from .const import (
|
|||
CONF_MIN_TEMP,
|
||||
CONF_STEP,
|
||||
CONF_TARGET_TEMP,
|
||||
DATA_TYPE_INT16,
|
||||
DATA_TYPE_INT32,
|
||||
DATA_TYPE_INT64,
|
||||
DATA_TYPE_UINT16,
|
||||
DATA_TYPE_UINT32,
|
||||
DATA_TYPE_UINT64,
|
||||
DataType,
|
||||
)
|
||||
from .modbus import ModbusHub
|
||||
|
||||
|
@ -113,12 +108,12 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
|
|||
float(kwargs[ATTR_TEMPERATURE]) - self._offset
|
||||
) / self._scale
|
||||
if self._data_type in (
|
||||
DATA_TYPE_INT16,
|
||||
DATA_TYPE_INT32,
|
||||
DATA_TYPE_INT64,
|
||||
DATA_TYPE_UINT16,
|
||||
DATA_TYPE_UINT32,
|
||||
DATA_TYPE_UINT64,
|
||||
DataType.INT16,
|
||||
DataType.INT32,
|
||||
DataType.INT64,
|
||||
DataType.UINT16,
|
||||
DataType.UINT32,
|
||||
DataType.UINT64,
|
||||
):
|
||||
target_temperature = int(target_temperature)
|
||||
as_bytes = struct.pack(self._structure, target_temperature)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Constants used in modbus integration."""
|
||||
from enum import Enum
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.climate.const import DOMAIN as CLIMATE_DOMAIN
|
||||
from homeassistant.components.cover import DOMAIN as COVER_DOMAIN
|
||||
|
@ -75,21 +77,26 @@ ATTR_VALUE = "value"
|
|||
ATTR_STATE = "state"
|
||||
ATTR_TEMPERATURE = "temperature"
|
||||
|
||||
|
||||
# data types
|
||||
DATA_TYPE_CUSTOM = "custom"
|
||||
DATA_TYPE_FLOAT = "float"
|
||||
DATA_TYPE_INT = "int"
|
||||
DATA_TYPE_UINT = "uint"
|
||||
DATA_TYPE_STRING = "string"
|
||||
DATA_TYPE_INT16 = "int16"
|
||||
DATA_TYPE_INT32 = "int32"
|
||||
DATA_TYPE_INT64 = "int64"
|
||||
DATA_TYPE_UINT16 = "uint16"
|
||||
DATA_TYPE_UINT32 = "uint32"
|
||||
DATA_TYPE_UINT64 = "uint64"
|
||||
DATA_TYPE_FLOAT16 = "float16"
|
||||
DATA_TYPE_FLOAT32 = "float32"
|
||||
DATA_TYPE_FLOAT64 = "float64"
|
||||
class DataType(str, Enum):
|
||||
"""Data types used by sensor etc."""
|
||||
|
||||
CUSTOM = "custom"
|
||||
FLOAT = "float" # deprecated
|
||||
INT = "int" # deprecated
|
||||
UINT = "uint" # deprecated
|
||||
STRING = "string"
|
||||
INT16 = "int16"
|
||||
INT32 = "int32"
|
||||
INT64 = "int64"
|
||||
UINT16 = "uint16"
|
||||
UINT32 = "uint32"
|
||||
UINT64 = "uint64"
|
||||
FLOAT16 = "float16"
|
||||
FLOAT32 = "float32"
|
||||
FLOAT64 = "float64"
|
||||
|
||||
|
||||
# call types
|
||||
CALL_TYPE_COIL = "coil"
|
||||
|
|
|
@ -30,57 +30,44 @@ from .const import (
|
|||
CONF_SWAP_BYTE,
|
||||
CONF_SWAP_NONE,
|
||||
CONF_WRITE_TYPE,
|
||||
DATA_TYPE_CUSTOM,
|
||||
DATA_TYPE_FLOAT,
|
||||
DATA_TYPE_FLOAT16,
|
||||
DATA_TYPE_FLOAT32,
|
||||
DATA_TYPE_FLOAT64,
|
||||
DATA_TYPE_INT,
|
||||
DATA_TYPE_INT16,
|
||||
DATA_TYPE_INT32,
|
||||
DATA_TYPE_INT64,
|
||||
DATA_TYPE_STRING,
|
||||
DATA_TYPE_UINT,
|
||||
DATA_TYPE_UINT16,
|
||||
DATA_TYPE_UINT32,
|
||||
DATA_TYPE_UINT64,
|
||||
DEFAULT_HUB,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
PLATFORMS,
|
||||
SERIAL,
|
||||
DataType,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
OLD_DATA_TYPES = {
|
||||
DATA_TYPE_INT: {
|
||||
1: DATA_TYPE_INT16,
|
||||
2: DATA_TYPE_INT32,
|
||||
4: DATA_TYPE_INT64,
|
||||
DataType.INT: {
|
||||
1: DataType.INT16,
|
||||
2: DataType.INT32,
|
||||
4: DataType.INT64,
|
||||
},
|
||||
DATA_TYPE_UINT: {
|
||||
1: DATA_TYPE_UINT16,
|
||||
2: DATA_TYPE_UINT32,
|
||||
4: DATA_TYPE_UINT64,
|
||||
DataType.UINT: {
|
||||
1: DataType.UINT16,
|
||||
2: DataType.UINT32,
|
||||
4: DataType.UINT64,
|
||||
},
|
||||
DATA_TYPE_FLOAT: {
|
||||
1: DATA_TYPE_FLOAT16,
|
||||
2: DATA_TYPE_FLOAT32,
|
||||
4: DATA_TYPE_FLOAT64,
|
||||
DataType.FLOAT: {
|
||||
1: DataType.FLOAT16,
|
||||
2: DataType.FLOAT32,
|
||||
4: DataType.FLOAT64,
|
||||
},
|
||||
}
|
||||
ENTRY = namedtuple("ENTRY", ["struct_id", "register_count"])
|
||||
DEFAULT_STRUCT_FORMAT = {
|
||||
DATA_TYPE_INT16: ENTRY("h", 1),
|
||||
DATA_TYPE_INT32: ENTRY("i", 2),
|
||||
DATA_TYPE_INT64: ENTRY("q", 4),
|
||||
DATA_TYPE_UINT16: ENTRY("H", 1),
|
||||
DATA_TYPE_UINT32: ENTRY("I", 2),
|
||||
DATA_TYPE_UINT64: ENTRY("Q", 4),
|
||||
DATA_TYPE_FLOAT16: ENTRY("e", 1),
|
||||
DATA_TYPE_FLOAT32: ENTRY("f", 2),
|
||||
DATA_TYPE_FLOAT64: ENTRY("d", 4),
|
||||
DATA_TYPE_STRING: ENTRY("s", 1),
|
||||
DataType.INT16: ENTRY("h", 1),
|
||||
DataType.INT32: ENTRY("i", 2),
|
||||
DataType.INT64: ENTRY("q", 4),
|
||||
DataType.UINT16: ENTRY("H", 1),
|
||||
DataType.UINT32: ENTRY("I", 2),
|
||||
DataType.UINT64: ENTRY("Q", 4),
|
||||
DataType.FLOAT16: ENTRY("e", 1),
|
||||
DataType.FLOAT32: ENTRY("f", 2),
|
||||
DataType.FLOAT64: ENTRY("d", 4),
|
||||
DataType.STRING: ENTRY("s", 1),
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,7 +79,7 @@ def struct_validator(config: dict[str, Any]) -> dict[str, Any]:
|
|||
name = config[CONF_NAME]
|
||||
structure = config.get(CONF_STRUCTURE)
|
||||
swap_type = config.get(CONF_SWAP)
|
||||
if data_type in (DATA_TYPE_INT, DATA_TYPE_UINT, DATA_TYPE_FLOAT):
|
||||
if data_type in (DataType.INT, DataType.UINT, DataType.FLOAT):
|
||||
error = f"{name} with {data_type} is not valid, trying to convert"
|
||||
_LOGGER.warning(error)
|
||||
try:
|
||||
|
@ -101,7 +88,7 @@ def struct_validator(config: dict[str, Any]) -> dict[str, Any]:
|
|||
except KeyError as exp:
|
||||
error = f"{name} cannot convert automatically {data_type}"
|
||||
raise vol.Invalid(error) from exp
|
||||
if config[CONF_DATA_TYPE] != DATA_TYPE_CUSTOM:
|
||||
if config[CONF_DATA_TYPE] != DataType.CUSTOM:
|
||||
if structure:
|
||||
error = f"{name} structure: cannot be mixed with {data_type}"
|
||||
raise vol.Invalid(error)
|
||||
|
|
|
@ -8,10 +8,7 @@ from homeassistant.components.modbus.const import (
|
|||
CONF_DATA_TYPE,
|
||||
CONF_LAZY_ERROR,
|
||||
CONF_TARGET_TEMP,
|
||||
DATA_TYPE_FLOAT32,
|
||||
DATA_TYPE_FLOAT64,
|
||||
DATA_TYPE_INT16,
|
||||
DATA_TYPE_INT32,
|
||||
DataType,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
|
@ -128,7 +125,7 @@ async def test_service_climate_update(hass, mock_modbus, mock_ha):
|
|||
CONF_TARGET_TEMP: 117,
|
||||
CONF_ADDRESS: 117,
|
||||
CONF_SLAVE: 10,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT16,
|
||||
CONF_DATA_TYPE: DataType.INT16,
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -143,7 +140,7 @@ async def test_service_climate_update(hass, mock_modbus, mock_ha):
|
|||
CONF_TARGET_TEMP: 117,
|
||||
CONF_ADDRESS: 117,
|
||||
CONF_SLAVE: 10,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT32,
|
||||
CONF_DATA_TYPE: DataType.INT32,
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -158,7 +155,7 @@ async def test_service_climate_update(hass, mock_modbus, mock_ha):
|
|||
CONF_TARGET_TEMP: 117,
|
||||
CONF_ADDRESS: 117,
|
||||
CONF_SLAVE: 10,
|
||||
CONF_DATA_TYPE: DATA_TYPE_FLOAT32,
|
||||
CONF_DATA_TYPE: DataType.FLOAT32,
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -173,7 +170,7 @@ async def test_service_climate_update(hass, mock_modbus, mock_ha):
|
|||
CONF_TARGET_TEMP: 117,
|
||||
CONF_ADDRESS: 117,
|
||||
CONF_SLAVE: 10,
|
||||
CONF_DATA_TYPE: DATA_TYPE_FLOAT64,
|
||||
CONF_DATA_TYPE: DataType.FLOAT64,
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -46,9 +46,6 @@ from homeassistant.components.modbus.const import (
|
|||
CONF_SWAP,
|
||||
CONF_SWAP_BYTE,
|
||||
CONF_SWAP_WORD,
|
||||
DATA_TYPE_CUSTOM,
|
||||
DATA_TYPE_INT,
|
||||
DATA_TYPE_STRING,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
MODBUS_DOMAIN as DOMAIN,
|
||||
RTUOVERTCP,
|
||||
|
@ -59,6 +56,7 @@ from homeassistant.components.modbus.const import (
|
|||
SERVICE_WRITE_REGISTER,
|
||||
TCP,
|
||||
UDP,
|
||||
DataType,
|
||||
)
|
||||
from homeassistant.components.modbus.validators import (
|
||||
duplicate_entity_validator,
|
||||
|
@ -142,23 +140,23 @@ async def test_number_validator():
|
|||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_STRING,
|
||||
CONF_DATA_TYPE: DataType.STRING,
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SWAP: CONF_SWAP_BYTE,
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: ">i",
|
||||
CONF_SWAP: CONF_SWAP_BYTE,
|
||||
},
|
||||
|
@ -178,36 +176,36 @@ async def test_ok_struct_validator(do_config):
|
|||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 8,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 8,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 8,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: "no good",
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 20,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: ">f",
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: ">f",
|
||||
CONF_SWAP: CONF_SWAP_WORD,
|
||||
},
|
||||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_STRING,
|
||||
CONF_DATA_TYPE: DataType.STRING,
|
||||
CONF_STRUCTURE: ">f",
|
||||
CONF_SWAP: CONF_SWAP_WORD,
|
||||
},
|
||||
|
|
|
@ -14,11 +14,7 @@ from homeassistant.components.modbus.const import (
|
|||
CONF_SWAP_NONE,
|
||||
CONF_SWAP_WORD,
|
||||
CONF_SWAP_WORD_BYTE,
|
||||
DATA_TYPE_CUSTOM,
|
||||
DATA_TYPE_FLOAT,
|
||||
DATA_TYPE_INT,
|
||||
DATA_TYPE_STRING,
|
||||
DATA_TYPE_UINT,
|
||||
DataType,
|
||||
)
|
||||
from homeassistant.components.sensor import (
|
||||
CONF_STATE_CLASS,
|
||||
|
@ -148,7 +144,7 @@ async def test_config_sensor(hass, mock_modbus):
|
|||
CONF_ADDRESS: 1234,
|
||||
CONF_COUNT: 8,
|
||||
CONF_PRECISION: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: ">no struct",
|
||||
},
|
||||
]
|
||||
|
@ -163,7 +159,7 @@ async def test_config_sensor(hass, mock_modbus):
|
|||
CONF_ADDRESS: 1234,
|
||||
CONF_COUNT: 2,
|
||||
CONF_PRECISION: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: ">4f",
|
||||
},
|
||||
]
|
||||
|
@ -176,7 +172,7 @@ async def test_config_sensor(hass, mock_modbus):
|
|||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_ADDRESS: 1234,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_COUNT: 4,
|
||||
CONF_SWAP: CONF_SWAP_NONE,
|
||||
CONF_STRUCTURE: "invalid",
|
||||
|
@ -191,7 +187,7 @@ async def test_config_sensor(hass, mock_modbus):
|
|||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_ADDRESS: 1234,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_COUNT: 4,
|
||||
CONF_SWAP: CONF_SWAP_NONE,
|
||||
CONF_STRUCTURE: "",
|
||||
|
@ -206,7 +202,7 @@ async def test_config_sensor(hass, mock_modbus):
|
|||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_ADDRESS: 1234,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_COUNT: 4,
|
||||
CONF_SWAP: CONF_SWAP_NONE,
|
||||
CONF_STRUCTURE: "1s",
|
||||
|
@ -221,7 +217,7 @@ async def test_config_sensor(hass, mock_modbus):
|
|||
{
|
||||
CONF_NAME: TEST_ENTITY_NAME,
|
||||
CONF_ADDRESS: 1234,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_COUNT: 1,
|
||||
CONF_STRUCTURE: "2s",
|
||||
CONF_SWAP: CONF_SWAP_WORD,
|
||||
|
@ -258,7 +254,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -276,7 +272,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 13,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -288,7 +284,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: 3,
|
||||
CONF_OFFSET: 13,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -300,7 +296,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 3,
|
||||
CONF_OFFSET: 13,
|
||||
CONF_PRECISION: 4,
|
||||
|
@ -312,7 +308,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: 1.5,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -324,7 +320,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: "1.5",
|
||||
CONF_OFFSET: "5",
|
||||
CONF_PRECISION: "1",
|
||||
|
@ -336,7 +332,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: 2.4,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 2,
|
||||
|
@ -348,7 +344,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: -10.3,
|
||||
CONF_PRECISION: 1,
|
||||
|
@ -360,7 +356,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -372,7 +368,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -384,7 +380,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 4,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -396,7 +392,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 4,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 2,
|
||||
CONF_OFFSET: 3,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -408,7 +404,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 4,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 2.0,
|
||||
CONF_OFFSET: 3.0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -421,7 +417,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_INPUT,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -434,7 +430,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_HOLDING,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -447,7 +443,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_HOLDING,
|
||||
CONF_DATA_TYPE: DATA_TYPE_FLOAT,
|
||||
CONF_DATA_TYPE: DataType.FLOAT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 5,
|
||||
|
@ -460,7 +456,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
{
|
||||
CONF_COUNT: 8,
|
||||
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_HOLDING,
|
||||
CONF_DATA_TYPE: DATA_TYPE_STRING,
|
||||
CONF_DATA_TYPE: DataType.STRING,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -473,7 +469,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
{
|
||||
CONF_COUNT: 8,
|
||||
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_HOLDING,
|
||||
CONF_DATA_TYPE: DATA_TYPE_STRING,
|
||||
CONF_DATA_TYPE: DataType.STRING,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -486,7 +482,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_INPUT_TYPE: CALL_TYPE_REGISTER_INPUT,
|
||||
CONF_DATA_TYPE: DATA_TYPE_UINT,
|
||||
CONF_DATA_TYPE: DataType.UINT,
|
||||
CONF_SCALE: 1,
|
||||
CONF_OFFSET: 0,
|
||||
CONF_PRECISION: 0,
|
||||
|
@ -498,7 +494,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SWAP: CONF_SWAP_NONE,
|
||||
},
|
||||
[0x0102],
|
||||
|
@ -508,7 +504,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SWAP: CONF_SWAP_BYTE,
|
||||
},
|
||||
[0x0201],
|
||||
|
@ -518,7 +514,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SWAP: CONF_SWAP_BYTE,
|
||||
},
|
||||
[0x0102, 0x0304],
|
||||
|
@ -528,7 +524,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SWAP: CONF_SWAP_WORD,
|
||||
},
|
||||
[0x0102, 0x0304],
|
||||
|
@ -538,7 +534,7 @@ async def test_config_wrong_struct_sensor(hass, error_message, mock_modbus, capl
|
|||
(
|
||||
{
|
||||
CONF_COUNT: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
CONF_SWAP: CONF_SWAP_WORD_BYTE,
|
||||
},
|
||||
[0x0102, 0x0304],
|
||||
|
@ -610,7 +606,7 @@ async def test_lazy_error_sensor(hass, mock_do_cycle, start_expect, end_expect):
|
|||
{
|
||||
CONF_COUNT: 8,
|
||||
CONF_PRECISION: 2,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: ">4f",
|
||||
},
|
||||
# floats: 7.931250095367432, 10.600000381469727,
|
||||
|
@ -622,7 +618,7 @@ async def test_lazy_error_sensor(hass, mock_do_cycle, start_expect, end_expect):
|
|||
{
|
||||
CONF_COUNT: 4,
|
||||
CONF_PRECISION: 0,
|
||||
CONF_DATA_TYPE: DATA_TYPE_CUSTOM,
|
||||
CONF_DATA_TYPE: DataType.CUSTOM,
|
||||
CONF_STRUCTURE: ">2i",
|
||||
},
|
||||
[0x0000, 0x0100, 0x0000, 0x0032],
|
||||
|
@ -632,7 +628,7 @@ async def test_lazy_error_sensor(hass, mock_do_cycle, start_expect, end_expect):
|
|||
{
|
||||
CONF_COUNT: 1,
|
||||
CONF_PRECISION: 0,
|
||||
CONF_DATA_TYPE: DATA_TYPE_INT,
|
||||
CONF_DATA_TYPE: DataType.INT,
|
||||
},
|
||||
[0x0101],
|
||||
"257",
|
||||
|
|
Loading…
Reference in New Issue