From 2e2b340b1ea83f18085235ac31ee47782620ffbd Mon Sep 17 00:00:00 2001 From: jan iversen Date: Wed, 21 Jul 2021 07:48:02 +0200 Subject: [PATCH] Set modbus entity to non-available unless scan_interval=0 (#53155) --- homeassistant/components/modbus/base_platform.py | 1 + tests/components/modbus/test_binary_sensor.py | 2 ++ tests/components/modbus/test_climate.py | 2 ++ tests/components/modbus/test_cover.py | 3 +++ tests/components/modbus/test_fan.py | 4 ++++ tests/components/modbus/test_light.py | 4 ++++ tests/components/modbus/test_sensor.py | 2 ++ tests/components/modbus/test_switch.py | 3 +++ 8 files changed, 21 insertions(+) diff --git a/homeassistant/components/modbus/base_platform.py b/homeassistant/components/modbus/base_platform.py index 39ec283519a..0b612c3ecf5 100644 --- a/homeassistant/components/modbus/base_platform.py +++ b/homeassistant/components/modbus/base_platform.py @@ -68,6 +68,7 @@ class BasePlatform(Entity): self._value = None self._available = True self._scan_interval = int(entry[CONF_SCAN_INTERVAL]) + self._available = self._scan_interval == 0 self._call_active = False @abstractmethod diff --git a/tests/components/modbus/test_binary_sensor.py b/tests/components/modbus/test_binary_sensor.py index e9c178ff025..e77fd380a22 100644 --- a/tests/components/modbus/test_binary_sensor.py +++ b/tests/components/modbus/test_binary_sensor.py @@ -12,6 +12,7 @@ from homeassistant.const import ( CONF_BINARY_SENSORS, CONF_DEVICE_CLASS, CONF_NAME, + CONF_SCAN_INTERVAL, CONF_SLAVE, STATE_OFF, STATE_ON, @@ -144,6 +145,7 @@ async def test_service_binary_sensor_update(hass, mock_pymodbus): { CONF_NAME: SENSOR_NAME, CONF_ADDRESS: 51, + CONF_SCAN_INTERVAL: 0, } ] }, diff --git a/tests/components/modbus/test_climate.py b/tests/components/modbus/test_climate.py index b872f4fe302..97d2c32ba69 100644 --- a/tests/components/modbus/test_climate.py +++ b/tests/components/modbus/test_climate.py @@ -104,6 +104,7 @@ async def test_service_climate_update(hass, mock_pymodbus): CONF_TARGET_TEMP: 117, CONF_ADDRESS: 117, CONF_SLAVE: 10, + CONF_SCAN_INTERVAL: 0, } ] } @@ -176,6 +177,7 @@ test_value.attributes = {ATTR_TEMPERATURE: 37} CONF_NAME: CLIMATE_NAME, CONF_TARGET_TEMP: 117, CONF_ADDRESS: 117, + CONF_SCAN_INTERVAL: 0, } ], }, diff --git a/tests/components/modbus/test_cover.py b/tests/components/modbus/test_cover.py index 37274603bee..8d7e7e39cf8 100644 --- a/tests/components/modbus/test_cover.py +++ b/tests/components/modbus/test_cover.py @@ -211,6 +211,7 @@ async def test_service_cover_update(hass, mock_pymodbus): CONF_STATE_CLOSING: 3, CONF_STATUS_REGISTER: 1234, CONF_STATUS_REGISTER_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, } ] }, @@ -232,11 +233,13 @@ async def test_service_cover_move(hass, mock_pymodbus): CONF_NAME: COVER_NAME, CONF_ADDRESS: 1234, CONF_STATUS_REGISTER_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, }, { CONF_NAME: f"{COVER_NAME}2", CONF_INPUT_TYPE: CALL_TYPE_COIL, CONF_ADDRESS: 1234, + CONF_SCAN_INTERVAL: 0, }, ] } diff --git a/tests/components/modbus/test_fan.py b/tests/components/modbus/test_fan.py index 4eeb094130b..13714d6bd0e 100644 --- a/tests/components/modbus/test_fan.py +++ b/tests/components/modbus/test_fan.py @@ -23,6 +23,7 @@ from homeassistant.const import ( CONF_HOST, CONF_NAME, CONF_PORT, + CONF_SCAN_INTERVAL, CONF_SLAVE, CONF_TYPE, STATE_OFF, @@ -195,6 +196,7 @@ async def test_all_fan(hass, call_type, regs, verify, expected): { CONF_NAME: FAN_NAME, CONF_ADDRESS: 1234, + CONF_SCAN_INTERVAL: 0, } ] }, @@ -219,11 +221,13 @@ async def test_fan_service_turn(hass, caplog, mock_pymodbus): CONF_NAME: FAN_NAME, CONF_ADDRESS: 17, CONF_WRITE_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, }, { CONF_NAME: f"{FAN_NAME}2", CONF_ADDRESS: 17, CONF_WRITE_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, CONF_VERIFY: {}, }, ], diff --git a/tests/components/modbus/test_light.py b/tests/components/modbus/test_light.py index e962b69a2a6..c7b9b820934 100644 --- a/tests/components/modbus/test_light.py +++ b/tests/components/modbus/test_light.py @@ -23,6 +23,7 @@ from homeassistant.const import ( CONF_LIGHTS, CONF_NAME, CONF_PORT, + CONF_SCAN_INTERVAL, CONF_SLAVE, CONF_TYPE, STATE_OFF, @@ -195,6 +196,7 @@ async def test_all_light(hass, call_type, regs, verify, expected): { CONF_NAME: LIGHT_NAME, CONF_ADDRESS: 1234, + CONF_SCAN_INTERVAL: 0, } ] }, @@ -219,11 +221,13 @@ async def test_light_service_turn(hass, caplog, mock_pymodbus): CONF_NAME: LIGHT_NAME, CONF_ADDRESS: 17, CONF_WRITE_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, }, { CONF_NAME: f"{LIGHT_NAME}2", CONF_ADDRESS: 17, CONF_WRITE_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, CONF_VERIFY: {}, }, ], diff --git a/tests/components/modbus/test_sensor.py b/tests/components/modbus/test_sensor.py index a3433a504b8..9b0c868f8cb 100644 --- a/tests/components/modbus/test_sensor.py +++ b/tests/components/modbus/test_sensor.py @@ -29,6 +29,7 @@ from homeassistant.const import ( CONF_DEVICE_CLASS, CONF_NAME, CONF_OFFSET, + CONF_SCAN_INTERVAL, CONF_SENSORS, CONF_SLAVE, CONF_STRUCTURE, @@ -578,6 +579,7 @@ async def test_struct_sensor(hass, cfg, regs, expected): { CONF_NAME: SENSOR_NAME, CONF_ADDRESS: 51, + CONF_SCAN_INTERVAL: 0, } ] }, diff --git a/tests/components/modbus/test_switch.py b/tests/components/modbus/test_switch.py index b31ca12c48b..c620429aad2 100644 --- a/tests/components/modbus/test_switch.py +++ b/tests/components/modbus/test_switch.py @@ -210,6 +210,7 @@ async def test_all_switch(hass, call_type, regs, verify, expected): { CONF_NAME: SWITCH_NAME, CONF_ADDRESS: 1234, + CONF_SCAN_INTERVAL: 0, } ] }, @@ -234,11 +235,13 @@ async def test_switch_service_turn(hass, caplog, mock_pymodbus): CONF_NAME: SWITCH_NAME, CONF_ADDRESS: 17, CONF_WRITE_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, }, { CONF_NAME: f"{SWITCH_NAME}2", CONF_ADDRESS: 17, CONF_WRITE_TYPE: CALL_TYPE_REGISTER_HOLDING, + CONF_SCAN_INTERVAL: 0, CONF_VERIFY: {}, }, ],