mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Fix modbus typing (#49938)
Add changes needed to please mypy and follow the coding rules of the project.
This commit is contained in:
parent
c69eeddc7b
commit
f0ec9c38b0
@ -35,7 +35,6 @@ from .const import (
|
|||||||
DEFAULT_SCAN_INTERVAL,
|
DEFAULT_SCAN_INTERVAL,
|
||||||
MODBUS_DOMAIN,
|
MODBUS_DOMAIN,
|
||||||
)
|
)
|
||||||
from .modbus import ModbusHub
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -84,14 +83,12 @@ async def async_setup_platform(
|
|||||||
CONF_NAME: "no name",
|
CONF_NAME: "no name",
|
||||||
CONF_BINARY_SENSORS: config[CONF_INPUTS],
|
CONF_BINARY_SENSORS: config[CONF_INPUTS],
|
||||||
}
|
}
|
||||||
config = None
|
|
||||||
|
|
||||||
for entry in discovery_info[CONF_BINARY_SENSORS]:
|
for entry in discovery_info[CONF_BINARY_SENSORS]:
|
||||||
if CONF_HUB in entry:
|
if CONF_HUB in entry:
|
||||||
# from old config!
|
hub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
|
||||||
hub: ModbusHub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
|
|
||||||
else:
|
else:
|
||||||
hub: ModbusHub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]
|
hub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]
|
||||||
if CONF_SCAN_INTERVAL not in entry:
|
if CONF_SCAN_INTERVAL not in entry:
|
||||||
entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL
|
entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL
|
||||||
sensors.append(
|
sensors.append(
|
||||||
|
@ -242,7 +242,7 @@ class ModbusThermostat(ClimateEntity):
|
|||||||
)
|
)
|
||||||
if result is None:
|
if result is None:
|
||||||
self._available = False
|
self._available = False
|
||||||
return
|
return -1
|
||||||
|
|
||||||
byte_string = b"".join(
|
byte_string = b"".join(
|
||||||
[x.to_bytes(2, byteorder="big") for x in result.registers]
|
[x.to_bytes(2, byteorder="big") for x in result.registers]
|
||||||
@ -255,11 +255,11 @@ class ModbusThermostat(ClimateEntity):
|
|||||||
)
|
)
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
val = val[0]
|
val2 = val[0]
|
||||||
register_value = format(
|
register_value = format(
|
||||||
(self._scale * val) + self._offset, f".{self._precision}f"
|
(self._scale * val2) + self._offset, f".{self._precision}f"
|
||||||
)
|
)
|
||||||
register_value = float(register_value)
|
register_value2 = float(register_value)
|
||||||
self._available = True
|
self._available = True
|
||||||
|
|
||||||
return register_value
|
return register_value2
|
||||||
|
@ -58,7 +58,6 @@ from .const import (
|
|||||||
DEFAULT_STRUCT_FORMAT,
|
DEFAULT_STRUCT_FORMAT,
|
||||||
MODBUS_DOMAIN,
|
MODBUS_DOMAIN,
|
||||||
)
|
)
|
||||||
from .modbus import ModbusHub
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -120,7 +119,6 @@ async def async_setup_platform(
|
|||||||
entry[CONF_INPUT_TYPE] = entry[CONF_REGISTER_TYPE]
|
entry[CONF_INPUT_TYPE] = entry[CONF_REGISTER_TYPE]
|
||||||
del entry[CONF_REGISTER]
|
del entry[CONF_REGISTER]
|
||||||
del entry[CONF_REGISTER_TYPE]
|
del entry[CONF_REGISTER_TYPE]
|
||||||
config = None
|
|
||||||
|
|
||||||
for entry in discovery_info[CONF_SENSORS]:
|
for entry in discovery_info[CONF_SENSORS]:
|
||||||
if entry[CONF_DATA_TYPE] == DATA_TYPE_STRING:
|
if entry[CONF_DATA_TYPE] == DATA_TYPE_STRING:
|
||||||
@ -175,9 +173,9 @@ async def async_setup_platform(
|
|||||||
continue
|
continue
|
||||||
if CONF_HUB in entry:
|
if CONF_HUB in entry:
|
||||||
# from old config!
|
# from old config!
|
||||||
hub: ModbusHub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
|
hub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
|
||||||
else:
|
else:
|
||||||
hub: ModbusHub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]
|
hub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]
|
||||||
if CONF_SCAN_INTERVAL not in entry:
|
if CONF_SCAN_INTERVAL not in entry:
|
||||||
entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL
|
entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL
|
||||||
sensors.append(
|
sensors.append(
|
||||||
|
3
mypy.ini
3
mypy.ini
@ -993,9 +993,6 @@ ignore_errors = true
|
|||||||
[mypy-homeassistant.components.mobile_app.*]
|
[mypy-homeassistant.components.mobile_app.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
[mypy-homeassistant.components.modbus.*]
|
|
||||||
ignore_errors = true
|
|
||||||
|
|
||||||
[mypy-homeassistant.components.motion_blinds.*]
|
[mypy-homeassistant.components.motion_blinds.*]
|
||||||
ignore_errors = true
|
ignore_errors = true
|
||||||
|
|
||||||
|
@ -134,7 +134,6 @@ IGNORED_MODULES: Final[list[str]] = [
|
|||||||
"homeassistant.components.metoffice.*",
|
"homeassistant.components.metoffice.*",
|
||||||
"homeassistant.components.minecraft_server.*",
|
"homeassistant.components.minecraft_server.*",
|
||||||
"homeassistant.components.mobile_app.*",
|
"homeassistant.components.mobile_app.*",
|
||||||
"homeassistant.components.modbus.*",
|
|
||||||
"homeassistant.components.motion_blinds.*",
|
"homeassistant.components.motion_blinds.*",
|
||||||
"homeassistant.components.motioneye.*",
|
"homeassistant.components.motioneye.*",
|
||||||
"homeassistant.components.mqtt.*",
|
"homeassistant.components.mqtt.*",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user