Remove pragma from discover check. (#68002)
This commit is contained in:
parent
4de59b065a
commit
d2e5c85429
13 changed files with 88 additions and 7 deletions
|
@ -39,7 +39,7 @@ async def async_setup_platform(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Modbus binary sensors."""
|
"""Set up the Modbus binary sensors."""
|
||||||
|
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
sensors: list[ModbusBinarySensor | SlaveSensor] = []
|
sensors: list[ModbusBinarySensor | SlaveSensor] = []
|
||||||
|
|
|
@ -45,7 +45,7 @@ async def async_setup_platform(
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Read configuration and create Modbus cover."""
|
"""Read configuration and create Modbus cover."""
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
covers = []
|
covers = []
|
||||||
|
|
|
@ -24,7 +24,7 @@ async def async_setup_platform(
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Read configuration and create Modbus fans."""
|
"""Read configuration and create Modbus fans."""
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
fans = []
|
fans = []
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ async def async_setup_platform(
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Read configuration and create Modbus lights."""
|
"""Read configuration and create Modbus lights."""
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
lights = []
|
lights = []
|
||||||
|
|
|
@ -34,7 +34,7 @@ async def async_setup_platform(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Modbus sensors."""
|
"""Set up the Modbus sensors."""
|
||||||
|
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
sensors: list[ModbusRegisterSensor | SlaveSensor] = []
|
sensors: list[ModbusRegisterSensor | SlaveSensor] = []
|
||||||
|
|
|
@ -25,7 +25,7 @@ async def async_setup_platform(
|
||||||
"""Read configuration and create Modbus switches."""
|
"""Read configuration and create Modbus switches."""
|
||||||
switches = []
|
switches = []
|
||||||
|
|
||||||
if discovery_info is None: # pragma: no cover
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
for entry in discovery_info[CONF_SWITCHES]:
|
for entry in discovery_info[CONF_SWITCHES]:
|
||||||
|
|
|
@ -8,6 +8,7 @@ from homeassistant.components.modbus.const import (
|
||||||
CONF_INPUT_TYPE,
|
CONF_INPUT_TYPE,
|
||||||
CONF_LAZY_ERROR,
|
CONF_LAZY_ERROR,
|
||||||
CONF_SLAVE_COUNT,
|
CONF_SLAVE_COUNT,
|
||||||
|
MODBUS_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ADDRESS,
|
CONF_ADDRESS,
|
||||||
|
@ -22,6 +23,7 @@ from homeassistant.const import (
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
||||||
|
|
||||||
|
@ -377,3 +379,15 @@ async def test_slave_binary_sensor(hass, expected, slaves, mock_do_cycle):
|
||||||
for i in range(len(slaves)):
|
for i in range(len(slaves)):
|
||||||
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}_{i+1}".replace(" ", "_")
|
entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}_{i+1}".replace(" ", "_")
|
||||||
assert hass.states.get(entity_id).state == slaves[i]
|
assert hass.states.get(entity_id).state == slaves[i]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_discovery_info_binary_sensor(hass, caplog):
|
||||||
|
"""Test setup without discovery info."""
|
||||||
|
assert SENSOR_DOMAIN not in hass.config.components
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
SENSOR_DOMAIN,
|
||||||
|
{SENSOR_DOMAIN: {"platform": MODBUS_DOMAIN}},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert SENSOR_DOMAIN in hass.config.components
|
||||||
|
|
|
@ -303,7 +303,7 @@ async def test_wrong_unpack_climate(hass, mock_do_cycle):
|
||||||
assert hass.states.get(ENTITY_ID).state == STATE_UNAVAILABLE
|
assert hass.states.get(ENTITY_ID).state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
async def test_no_discovery_info(hass, caplog):
|
async def test_no_discovery_info_climate(hass, caplog):
|
||||||
"""Test setup without discovery info."""
|
"""Test setup without discovery info."""
|
||||||
assert CLIMATE_DOMAIN not in hass.config.components
|
assert CLIMATE_DOMAIN not in hass.config.components
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.components.modbus.const import (
|
||||||
CONF_STATE_OPENING,
|
CONF_STATE_OPENING,
|
||||||
CONF_STATUS_REGISTER,
|
CONF_STATUS_REGISTER,
|
||||||
CONF_STATUS_REGISTER_TYPE,
|
CONF_STATUS_REGISTER_TYPE,
|
||||||
|
MODBUS_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ADDRESS,
|
CONF_ADDRESS,
|
||||||
|
@ -29,6 +30,7 @@ from homeassistant.const import (
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
||||||
|
|
||||||
|
@ -307,3 +309,15 @@ async def test_service_cover_move(hass, mock_modbus, mock_ha):
|
||||||
"cover", "close_cover", {"entity_id": ENTITY_ID2}, blocking=True
|
"cover", "close_cover", {"entity_id": ENTITY_ID2}, blocking=True
|
||||||
)
|
)
|
||||||
assert hass.states.get(ENTITY_ID2).state == STATE_UNAVAILABLE
|
assert hass.states.get(ENTITY_ID2).state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_discovery_info_cover(hass, caplog):
|
||||||
|
"""Test setup without discovery info."""
|
||||||
|
assert COVER_DOMAIN not in hass.config.components
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
COVER_DOMAIN,
|
||||||
|
{COVER_DOMAIN: {"platform": MODBUS_DOMAIN}},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert COVER_DOMAIN in hass.config.components
|
||||||
|
|
|
@ -29,6 +29,7 @@ from homeassistant.const import (
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .conftest import TEST_ENTITY_NAME, ReadResult
|
from .conftest import TEST_ENTITY_NAME, ReadResult
|
||||||
|
|
||||||
|
@ -309,3 +310,15 @@ async def test_service_fan_update(hass, mock_modbus, mock_ha):
|
||||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||||
)
|
)
|
||||||
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_discovery_info_fan(hass, caplog):
|
||||||
|
"""Test setup without discovery info."""
|
||||||
|
assert FAN_DOMAIN not in hass.config.components
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
FAN_DOMAIN,
|
||||||
|
{FAN_DOMAIN: {"platform": MODBUS_DOMAIN}},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert FAN_DOMAIN in hass.config.components
|
||||||
|
|
|
@ -29,6 +29,7 @@ from homeassistant.const import (
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .conftest import TEST_ENTITY_NAME, ReadResult
|
from .conftest import TEST_ENTITY_NAME, ReadResult
|
||||||
|
|
||||||
|
@ -309,3 +310,15 @@ async def test_service_light_update(hass, mock_modbus, mock_ha):
|
||||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||||
)
|
)
|
||||||
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_discovery_info_light(hass, caplog):
|
||||||
|
"""Test setup without discovery info."""
|
||||||
|
assert LIGHT_DOMAIN not in hass.config.components
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
LIGHT_DOMAIN,
|
||||||
|
{LIGHT_DOMAIN: {"platform": MODBUS_DOMAIN}},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert LIGHT_DOMAIN in hass.config.components
|
||||||
|
|
|
@ -15,6 +15,7 @@ from homeassistant.components.modbus.const import (
|
||||||
CONF_SWAP_NONE,
|
CONF_SWAP_NONE,
|
||||||
CONF_SWAP_WORD,
|
CONF_SWAP_WORD,
|
||||||
CONF_SWAP_WORD_BYTE,
|
CONF_SWAP_WORD_BYTE,
|
||||||
|
MODBUS_DOMAIN,
|
||||||
DataType,
|
DataType,
|
||||||
)
|
)
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
|
@ -36,6 +37,7 @@ from homeassistant.const import (
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
||||||
|
|
||||||
|
@ -820,3 +822,15 @@ async def test_service_sensor_update(hass, mock_modbus, mock_ha):
|
||||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||||
)
|
)
|
||||||
assert hass.states.get(ENTITY_ID).state == "32"
|
assert hass.states.get(ENTITY_ID).state == "32"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_discovery_info_sensor(hass, caplog):
|
||||||
|
"""Test setup without discovery info."""
|
||||||
|
assert SENSOR_DOMAIN not in hass.config.components
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
SENSOR_DOMAIN,
|
||||||
|
{SENSOR_DOMAIN: {"platform": MODBUS_DOMAIN}},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert SENSOR_DOMAIN in hass.config.components
|
||||||
|
|
|
@ -34,6 +34,7 @@ from homeassistant.const import (
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle
|
||||||
|
@ -395,3 +396,15 @@ async def test_delay_switch(hass, mock_modbus):
|
||||||
async_fire_time_changed(hass, now)
|
async_fire_time_changed(hass, now)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
||||||
|
|
||||||
|
|
||||||
|
async def test_no_discovery_info_switch(hass, caplog):
|
||||||
|
"""Test setup without discovery info."""
|
||||||
|
assert SWITCH_DOMAIN not in hass.config.components
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass,
|
||||||
|
SWITCH_DOMAIN,
|
||||||
|
{SWITCH_DOMAIN: {"platform": MODBUS_DOMAIN}},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert SWITCH_DOMAIN in hass.config.components
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue