Fix modbus switch "old style" config problem (#49352)

Fix that using CONF_HUB in switch, changed the hub for all
subsequent switches.
This commit is contained in:
jan iversen 2021-04-19 19:35:32 +02:00 committed by GitHub
parent a5806b59f2
commit 8acc3f0b03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View file

@ -89,10 +89,11 @@ async def async_setup_platform(
for entry in discovery_info[CONF_BINARY_SENSORS]:
if CONF_HUB in entry:
# from old config!
discovery_info[CONF_NAME] = entry[CONF_HUB]
hub: ModbusHub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]]
else:
hub: ModbusHub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]
if CONF_SCAN_INTERVAL not in entry:
entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL
hub: ModbusHub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]
sensors.append(
ModbusBinarySensor(
hub,