mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Remove "old" config from modbus binary_sensor (#51117)
This commit is contained in:
parent
81097dbe40
commit
e45196f9c9
@ -3,70 +3,19 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
||||||
|
from homeassistant.const import CONF_BINARY_SENSORS, CONF_NAME, STATE_ON
|
||||||
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.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .base_platform import BasePlatform
|
from .base_platform import BasePlatform
|
||||||
from .const import (
|
from .const import MODBUS_DOMAIN
|
||||||
CALL_TYPE_COIL,
|
|
||||||
CALL_TYPE_DISCRETE,
|
|
||||||
CONF_COILS,
|
|
||||||
CONF_HUB,
|
|
||||||
CONF_INPUT_TYPE,
|
|
||||||
CONF_INPUTS,
|
|
||||||
DEFAULT_HUB,
|
|
||||||
DEFAULT_SCAN_INTERVAL,
|
|
||||||
MODBUS_DOMAIN,
|
|
||||||
)
|
|
||||||
|
|
||||||
PARALLEL_UPDATES = 1
|
PARALLEL_UPDATES = 1
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
@ -76,23 +25,11 @@ async def async_setup_platform(
|
|||||||
"""Set up the Modbus binary sensors."""
|
"""Set up the Modbus binary sensors."""
|
||||||
sensors = []
|
sensors = []
|
||||||
|
|
||||||
# check for old config:
|
if discovery_info is None: # pragma: no cover
|
||||||
if discovery_info is None:
|
return
|
||||||
_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],
|
|
||||||
}
|
|
||||||
|
|
||||||
for entry in discovery_info[CONF_BINARY_SENSORS]:
|
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]]
|
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(ModbusBinarySensor(hub, entry))
|
sensors.append(ModbusBinarySensor(hub, entry))
|
||||||
|
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors)
|
||||||
|
@ -6,7 +6,6 @@ from homeassistant.components.modbus.const import (
|
|||||||
CALL_TYPE_COIL,
|
CALL_TYPE_COIL,
|
||||||
CALL_TYPE_DISCRETE,
|
CALL_TYPE_DISCRETE,
|
||||||
CONF_INPUT_TYPE,
|
CONF_INPUT_TYPE,
|
||||||
CONF_INPUTS,
|
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ADDRESS,
|
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
|
from tests.common import mock_restore_cache
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("do_discovery", [False, True])
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"do_options",
|
"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."""
|
"""Run test for binary sensor."""
|
||||||
sensor_name = "test_sensor"
|
sensor_name = "test_sensor"
|
||||||
config_sensor = {
|
config_sensor = {
|
||||||
@ -51,8 +49,8 @@ async def test_config_binary_sensor(hass, do_discovery, do_options):
|
|||||||
sensor_name,
|
sensor_name,
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
CONF_BINARY_SENSORS,
|
CONF_BINARY_SENSORS,
|
||||||
CONF_INPUTS,
|
None,
|
||||||
method_discovery=do_discovery,
|
method_discovery=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +93,7 @@ async def test_all_binary_sensor(hass, do_type, regs, expected):
|
|||||||
sensor_name,
|
sensor_name,
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
CONF_BINARY_SENSORS,
|
CONF_BINARY_SENSORS,
|
||||||
CONF_INPUTS,
|
None,
|
||||||
regs,
|
regs,
|
||||||
expected,
|
expected,
|
||||||
method_discovery=True,
|
method_discovery=True,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user