1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Fix modbus typing (#49938)

Add changes needed to please mypy and follow the coding rules
of the project.
This commit is contained in:
jan iversen 2021-05-03 22:45:21 +02:00 committed by GitHub
parent c69eeddc7b
commit f0ec9c38b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 18 deletions

View File

@ -35,7 +35,6 @@ from .const import (
DEFAULT_SCAN_INTERVAL,
MODBUS_DOMAIN,
)
from .modbus import ModbusHub
_LOGGER = logging.getLogger(__name__)
@ -84,14 +83,12 @@ async def async_setup_platform(
CONF_NAME: "no name",
CONF_BINARY_SENSORS: config[CONF_INPUTS],
}
config = None
for entry in discovery_info[CONF_BINARY_SENSORS]:
if CONF_HUB in entry:
# from old config!
hub: ModbusHub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
hub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
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:
entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL
sensors.append(

View File

@ -242,7 +242,7 @@ class ModbusThermostat(ClimateEntity):
)
if result is None:
self._available = False
return
return -1
byte_string = b"".join(
[x.to_bytes(2, byteorder="big") for x in result.registers]
@ -255,11 +255,11 @@ class ModbusThermostat(ClimateEntity):
)
return -1
val = val[0]
val2 = val[0]
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
return register_value
return register_value2

View File

@ -58,7 +58,6 @@ from .const import (
DEFAULT_STRUCT_FORMAT,
MODBUS_DOMAIN,
)
from .modbus import ModbusHub
_LOGGER = logging.getLogger(__name__)
@ -120,7 +119,6 @@ async def async_setup_platform(
entry[CONF_INPUT_TYPE] = entry[CONF_REGISTER_TYPE]
del entry[CONF_REGISTER]
del entry[CONF_REGISTER_TYPE]
config = None
for entry in discovery_info[CONF_SENSORS]:
if entry[CONF_DATA_TYPE] == DATA_TYPE_STRING:
@ -175,9 +173,9 @@ async def async_setup_platform(
continue
if CONF_HUB in entry:
# from old config!
hub: ModbusHub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
hub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
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:
entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL
sensors.append(

View File

@ -993,9 +993,6 @@ ignore_errors = true
[mypy-homeassistant.components.mobile_app.*]
ignore_errors = true
[mypy-homeassistant.components.modbus.*]
ignore_errors = true
[mypy-homeassistant.components.motion_blinds.*]
ignore_errors = true

View File

@ -134,7 +134,6 @@ IGNORED_MODULES: Final[list[str]] = [
"homeassistant.components.metoffice.*",
"homeassistant.components.minecraft_server.*",
"homeassistant.components.mobile_app.*",
"homeassistant.components.modbus.*",
"homeassistant.components.motion_blinds.*",
"homeassistant.components.motioneye.*",
"homeassistant.components.mqtt.*",