mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Propagate RFLink 'send_command' event (#43588)
* propagate send_command event * propagate send_command event
This commit is contained in:
parent
8b8a54b367
commit
c8950870a2
@ -67,6 +67,7 @@ SERVICE_SEND_COMMAND = "send_command"
|
|||||||
|
|
||||||
SIGNAL_AVAILABILITY = "rflink_device_available"
|
SIGNAL_AVAILABILITY = "rflink_device_available"
|
||||||
SIGNAL_HANDLE_EVENT = "rflink_handle_event_{}"
|
SIGNAL_HANDLE_EVENT = "rflink_handle_event_{}"
|
||||||
|
SIGNAL_EVENT = "rflink_event"
|
||||||
|
|
||||||
TMP_ENTITY = "tmp.{}"
|
TMP_ENTITY = "tmp.{}"
|
||||||
|
|
||||||
@ -140,6 +141,15 @@ async def async_setup(hass, config):
|
|||||||
)
|
)
|
||||||
):
|
):
|
||||||
_LOGGER.error("Failed Rflink command for %s", str(call.data))
|
_LOGGER.error("Failed Rflink command for %s", str(call.data))
|
||||||
|
else:
|
||||||
|
async_dispatcher_send(
|
||||||
|
hass,
|
||||||
|
SIGNAL_EVENT,
|
||||||
|
{
|
||||||
|
EVENT_KEY_ID: call.data.get(CONF_DEVICE_ID),
|
||||||
|
EVENT_KEY_COMMAND: call.data.get(CONF_COMMAND),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
hass.services.async_register(
|
hass.services.async_register(
|
||||||
DOMAIN, SERVICE_SEND_COMMAND, async_send_command, schema=SEND_COMMAND_SCHEMA
|
DOMAIN, SERVICE_SEND_COMMAND, async_send_command, schema=SEND_COMMAND_SCHEMA
|
||||||
@ -293,6 +303,7 @@ async def async_setup(hass, config):
|
|||||||
_LOGGER.info("Connected to Rflink")
|
_LOGGER.info("Connected to Rflink")
|
||||||
|
|
||||||
hass.async_create_task(connect())
|
hass.async_create_task(connect())
|
||||||
|
async_dispatcher_connect(hass, SIGNAL_EVENT, event_callback)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,6 +196,50 @@ async def test_send_command_invalid_arguments(hass, monkeypatch):
|
|||||||
assert not success, "send command should not succeed for unknown command"
|
assert not success, "send command should not succeed for unknown command"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_send_command_event_propagation(hass, monkeypatch):
|
||||||
|
"""Test event propagation for send_command service."""
|
||||||
|
domain = "light"
|
||||||
|
config = {
|
||||||
|
"rflink": {"port": "/dev/ttyABC0"},
|
||||||
|
domain: {
|
||||||
|
"platform": "rflink",
|
||||||
|
"devices": {
|
||||||
|
"protocol_0_1": {"name": "test1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# setup mocking rflink module
|
||||||
|
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
|
||||||
|
|
||||||
|
# default value = 'off'
|
||||||
|
assert hass.states.get(f"{domain}.test1").state == "off"
|
||||||
|
|
||||||
|
hass.async_create_task(
|
||||||
|
hass.services.async_call(
|
||||||
|
"rflink",
|
||||||
|
SERVICE_SEND_COMMAND,
|
||||||
|
{"device_id": "protocol_0_1", "command": "on"},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert protocol.send_command_ack.call_args_list[0][0][0] == "protocol_0_1"
|
||||||
|
assert protocol.send_command_ack.call_args_list[0][0][1] == "on"
|
||||||
|
assert hass.states.get(f"{domain}.test1").state == "on"
|
||||||
|
|
||||||
|
hass.async_create_task(
|
||||||
|
hass.services.async_call(
|
||||||
|
"rflink",
|
||||||
|
SERVICE_SEND_COMMAND,
|
||||||
|
{"device_id": "protocol_0_1", "command": "alloff"},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert protocol.send_command_ack.call_args_list[1][0][0] == "protocol_0_1"
|
||||||
|
assert protocol.send_command_ack.call_args_list[1][0][1] == "alloff"
|
||||||
|
assert hass.states.get(f"{domain}.test1").state == "off"
|
||||||
|
|
||||||
|
|
||||||
async def test_reconnecting_after_disconnect(hass, monkeypatch):
|
async def test_reconnecting_after_disconnect(hass, monkeypatch):
|
||||||
"""An unexpected disconnect should cause a reconnect."""
|
"""An unexpected disconnect should cause a reconnect."""
|
||||||
domain = "sensor"
|
domain = "sensor"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user