From e45196f9c961017ce0ecc70cbfaa1736869a1ed9 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Fri, 28 May 2021 12:06:46 +0200 Subject: [PATCH] Remove "old" config from modbus binary_sensor (#51117) --- .../components/modbus/binary_sensor.py | 75 ++----------------- tests/components/modbus/test_binary_sensor.py | 10 +-- 2 files changed, 10 insertions(+), 75 deletions(-) diff --git a/homeassistant/components/modbus/binary_sensor.py b/homeassistant/components/modbus/binary_sensor.py index c27fde6d946..bc586e2f24d 100644 --- a/homeassistant/components/modbus/binary_sensor.py +++ b/homeassistant/components/modbus/binary_sensor.py @@ -3,70 +3,19 @@ from __future__ import annotations import logging -import voluptuous as vol - -from homeassistant.components.binary_sensor import ( - DEVICE_CLASSES_SCHEMA, - PLATFORM_SCHEMA, - BinarySensorEntity, -) -from homeassistant.const import ( - CONF_ADDRESS, - CONF_BINARY_SENSORS, - CONF_DEVICE_CLASS, - CONF_NAME, - CONF_SCAN_INTERVAL, - CONF_SLAVE, - STATE_ON, -) +from homeassistant.components.binary_sensor import BinarySensorEntity +from homeassistant.const import CONF_BINARY_SENSORS, CONF_NAME, STATE_ON from homeassistant.core import HomeAssistant -from homeassistant.helpers import config_validation as cv from homeassistant.helpers.restore_state import RestoreEntity from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from .base_platform import BasePlatform -from .const import ( - CALL_TYPE_COIL, - CALL_TYPE_DISCRETE, - CONF_COILS, - CONF_HUB, - CONF_INPUT_TYPE, - CONF_INPUTS, - DEFAULT_HUB, - DEFAULT_SCAN_INTERVAL, - MODBUS_DOMAIN, -) +from .const import MODBUS_DOMAIN PARALLEL_UPDATES = 1 _LOGGER = logging.getLogger(__name__) -PLATFORM_SCHEMA = vol.All( - cv.deprecated(CONF_COILS, CONF_INPUTS), - PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_INPUTS): [ - vol.All( - cv.deprecated(CALL_TYPE_COIL, CONF_ADDRESS), - vol.Schema( - { - vol.Required(CONF_ADDRESS): cv.positive_int, - vol.Required(CONF_NAME): cv.string, - vol.Optional(CONF_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA, - vol.Optional(CONF_HUB, default=DEFAULT_HUB): cv.string, - vol.Optional(CONF_SLAVE): cv.positive_int, - vol.Optional( - CONF_INPUT_TYPE, default=CALL_TYPE_COIL - ): vol.In([CALL_TYPE_COIL, CALL_TYPE_DISCRETE]), - } - ), - ) - ] - } - ), -) - - async def async_setup_platform( hass: HomeAssistant, config: ConfigType, @@ -76,23 +25,11 @@ async def async_setup_platform( """Set up the Modbus binary sensors.""" sensors = [] - #  check for old config: - if discovery_info is None: - _LOGGER.warning( - "Binary_sensor configuration is deprecated, will be removed in a future release" - ) - discovery_info = { - CONF_NAME: "no name", - CONF_BINARY_SENSORS: config[CONF_INPUTS], - } + if discovery_info is None: # pragma: no cover + return for entry in discovery_info[CONF_BINARY_SENSORS]: - if CONF_HUB in entry: - hub = hass.data[MODBUS_DOMAIN][entry[CONF_HUB]] - else: - hub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]] - if CONF_SCAN_INTERVAL not in entry: - entry[CONF_SCAN_INTERVAL] = DEFAULT_SCAN_INTERVAL + hub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]] sensors.append(ModbusBinarySensor(hub, entry)) async_add_entities(sensors) diff --git a/tests/components/modbus/test_binary_sensor.py b/tests/components/modbus/test_binary_sensor.py index 5089d0271dd..ebf487b129d 100644 --- a/tests/components/modbus/test_binary_sensor.py +++ b/tests/components/modbus/test_binary_sensor.py @@ -6,7 +6,6 @@ from homeassistant.components.modbus.const import ( CALL_TYPE_COIL, CALL_TYPE_DISCRETE, CONF_INPUT_TYPE, - CONF_INPUTS, ) from homeassistant.const import ( CONF_ADDRESS, @@ -25,7 +24,6 @@ from .conftest import ReadResult, base_config_test, base_test, prepare_service_u from tests.common import mock_restore_cache -@pytest.mark.parametrize("do_discovery", [False, True]) @pytest.mark.parametrize( "do_options", [ @@ -37,7 +35,7 @@ from tests.common import mock_restore_cache }, ], ) -async def test_config_binary_sensor(hass, do_discovery, do_options): +async def test_config_binary_sensor(hass, do_options): """Run test for binary sensor.""" sensor_name = "test_sensor" config_sensor = { @@ -51,8 +49,8 @@ async def test_config_binary_sensor(hass, do_discovery, do_options): sensor_name, SENSOR_DOMAIN, CONF_BINARY_SENSORS, - CONF_INPUTS, - method_discovery=do_discovery, + None, + method_discovery=True, ) @@ -95,7 +93,7 @@ async def test_all_binary_sensor(hass, do_type, regs, expected): sensor_name, SENSOR_DOMAIN, CONF_BINARY_SENSORS, - CONF_INPUTS, + None, regs, expected, method_discovery=True,