Remove old config from cover, including tests (#51118)

* Remove old config and standardize new config.

* Add missing safeguard.
This commit is contained in:
jan iversen 2021-05-28 11:29:37 +02:00 committed by GitHub
parent d200f1e504
commit 47f016b340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 38 deletions

View File

@ -49,12 +49,7 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType | None = None,
):
"""Read configuration and create Modbus cover."""
if discovery_info is None:
_LOGGER.warning(
"You're trying to init Modbus Cover in an unsupported way."
" Check https://www.home-assistant.io/integrations/modbus/#configuring-platform-cover"
" and fix your configuration"
)
if discovery_info is None: # pragma: no cover
return
covers = []

View File

@ -20,7 +20,7 @@ async def async_setup_platform(
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
):
"""Read configuration and create Modbus fans."""
if discovery_info is None:
if discovery_info is None: # pragma: no cover
return
fans = []

View File

@ -20,8 +20,9 @@ async def async_setup_platform(
hass: HomeAssistant, config: ConfigType, async_add_entities, discovery_info=None
):
"""Read configuration and create Modbus lights."""
if discovery_info is None:
if discovery_info is None: # pragma: no cover
return
lights = []
for entry in discovery_info[CONF_LIGHTS]:
hub: ModbusHub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]

View File

@ -22,6 +22,9 @@ async def async_setup_platform(
"""Read configuration and create Modbus switches."""
switches = []
if discovery_info is None: # pragma: no cover
return
for entry in discovery_info[CONF_SWITCHES]:
hub: ModbusHub = hass.data[MODBUS_DOMAIN][discovery_info[CONF_NAME]]
switches.append(ModbusSwitch(hub, entry))

View File

@ -1,5 +1,4 @@
"""The tests for the Modbus cover component."""
import logging
from pymodbus.exceptions import ModbusException
import pytest
@ -158,35 +157,6 @@ async def test_register_cover(hass, regs, expected):
assert state == expected
@pytest.mark.parametrize("read_type", [CALL_TYPE_COIL, CONF_REGISTER])
async def test_unsupported_config_cover(hass, read_type, caplog):
"""
Run test for cover.
Initialize the Cover in the legacy manner via platform.
This test expects that the Cover won't be initialized, and that we get a config warning.
"""
device_name = "test_cover"
device_config = {CONF_NAME: device_name, read_type: 1234}
caplog.set_level(logging.WARNING)
caplog.clear()
await base_config_test(
hass,
device_config,
device_name,
COVER_DOMAIN,
CONF_COVERS,
None,
method_discovery=False,
expect_init_to_fail=True,
)
assert len(caplog.records) == 1
assert caplog.records[0].levelname == "WARNING"
async def test_service_cover_update(hass, mock_pymodbus):
"""Run test for service homeassistant.update_entity."""