Replace prepare_service_call with a simpler fixture in modbus (#53975)
* Convert prepare_service_call to a fixture.
This commit is contained in:
parent
4d93184197
commit
4ef9269790
8 changed files with 253 additions and 218 deletions
|
@ -33,7 +33,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .conftest import ReadResult, base_test, prepare_service_update
|
||||
from .conftest import ReadResult, base_test
|
||||
|
||||
LIGHT_NAME = "test_light"
|
||||
ENTITY_ID = f"{LIGHT_DOMAIN}.{LIGHT_NAME}"
|
||||
|
@ -277,30 +277,29 @@ async def test_light_service_turn(hass, caplog, mock_pymodbus):
|
|||
assert hass.states.get(ENTITY_ID).state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_service_light_update(hass, mock_pymodbus):
|
||||
@pytest.mark.parametrize(
|
||||
"do_config",
|
||||
[
|
||||
{
|
||||
CONF_LIGHTS: [
|
||||
{
|
||||
CONF_NAME: LIGHT_NAME,
|
||||
CONF_ADDRESS: 1234,
|
||||
CONF_WRITE_TYPE: CALL_TYPE_COIL,
|
||||
CONF_VERIFY: {},
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
)
|
||||
async def test_service_light_update(hass, mock_modbus, mock_ha):
|
||||
"""Run test for service homeassistant.update_entity."""
|
||||
|
||||
config = {
|
||||
CONF_LIGHTS: [
|
||||
{
|
||||
CONF_NAME: LIGHT_NAME,
|
||||
CONF_ADDRESS: 1234,
|
||||
CONF_WRITE_TYPE: CALL_TYPE_COIL,
|
||||
CONF_VERIFY: {},
|
||||
}
|
||||
]
|
||||
}
|
||||
mock_pymodbus.read_discrete_inputs.return_value = ReadResult([0x01])
|
||||
await prepare_service_update(
|
||||
hass,
|
||||
config,
|
||||
)
|
||||
await hass.services.async_call(
|
||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
||||
mock_pymodbus.read_coils.return_value = ReadResult([0x00])
|
||||
await hass.services.async_call(
|
||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_OFF
|
||||
mock_modbus.read_coils.return_value = ReadResult([0x01])
|
||||
await hass.services.async_call(
|
||||
"homeassistant", "update_entity", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
assert hass.states.get(ENTITY_ID).state == STATE_ON
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue