Replace rfxtrx entity events with integration events (#37565)
* Drop per entity events * Correct linting error * Drop keys()
This commit is contained in:
1 parent
d3b47b6d89
commit
87f6b7cdd4
14 files changed
+132
-183
No files matched your search
@@ -4,6 +4,11 @@ from homeassistant.components import rfxtrx
|
||||
|
||||
async def _signal_event(hass, packet_id):
|
||||
event = rfxtrx.get_rfx_object(packet_id)
|
||||
hass.helpers.dispatcher.async_dispatcher_send(rfxtrx.SIGNAL_EVENT, event)
|
||||
|
||||
await hass.async_add_executor_job(
|
||||
hass.data[rfxtrx.DATA_RFXOBJECT].event_callback, event,
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
return event
|
||||
@@ -50,6 +50,7 @@ async def test_one_pt2262(hass, rfxtrx):
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
state = hass.states.get("binary_sensor.pt2262_22670e")
|
||||
assert state
|
||||
@@ -119,6 +120,7 @@ async def test_discover(hass, rfxtrx):
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
await _signal_event(hass, "0b1100100118cdea02010f70")
|
||||
state = hass.states.get("binary_sensor.ac_118cdea_2")
|
||||
@@ -145,6 +147,7 @@ async def test_off_delay(hass, rfxtrx):
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
state = hass.states.get("binary_sensor.ac_118cdea_2")
|
||||
assert state
|
||||
|
||||
@@ -95,6 +95,7 @@ async def test_discover_covers(hass, rfxtrx):
|
||||
{"rfxtrx": {"device": "abcd", "dummy": True, "automatic_add": True}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
await _signal_event(hass, "0a140002f38cae010f0070")
|
||||
state = hass.states.get("cover.lightwaverf_siemens_f38cae_1")
|
||||
|
||||
@@ -66,68 +66,44 @@ async def test_fire_event(hass):
|
||||
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
||||
"dummy": True,
|
||||
"automatic_add": True,
|
||||
"devices": {"0b1100cd0213c7f210010f51": {rfxtrx.ATTR_FIRE_EVENT: True}},
|
||||
"devices": {
|
||||
"0b1100cd0213c7f210010f51": {rfxtrx.CONF_FIRE_EVENT: True},
|
||||
"0716000100900970": {rfxtrx.CONF_FIRE_EVENT: True},
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
calls = []
|
||||
|
||||
@callback
|
||||
def record_event(event):
|
||||
"""Add recorded event to set."""
|
||||
calls.append(event)
|
||||
assert event.event_type == "rfxtrx_event"
|
||||
calls.append(event.data)
|
||||
|
||||
hass.bus.async_listen(rfxtrx.EVENT_BUTTON_PRESSED, record_event)
|
||||
|
||||
state = hass.states.get("switch.ac_213c7f2_16")
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
hass.bus.async_listen(rfxtrx.const.EVENT_RFXTRX_EVENT, record_event)
|
||||
|
||||
await _signal_event(hass, "0b1100cd0213c7f210010f51")
|
||||
await _signal_event(hass, "0716000100900970")
|
||||
|
||||
state = hass.states.get("switch.ac_213c7f2_16")
|
||||
assert state
|
||||
assert state.state == "on"
|
||||
|
||||
assert any(
|
||||
call.data == {"entity_id": "switch.ac_213c7f2_16", "state": "on"}
|
||||
for call in calls
|
||||
)
|
||||
|
||||
|
||||
async def test_fire_event_sensor(hass):
|
||||
"""Test fire event."""
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
assert calls == [
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "/dev/serial/by-id/usb"
|
||||
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
||||
"dummy": True,
|
||||
"automatic_add": True,
|
||||
"devices": {"0a520802060100ff0e0269": {rfxtrx.ATTR_FIRE_EVENT: True}},
|
||||
}
|
||||
"packet_type": 17,
|
||||
"sub_type": 0,
|
||||
"type_string": "AC",
|
||||
"id_string": "213c7f2:16",
|
||||
"data": "0b1100cd0213c7f210010f51",
|
||||
"values": {"Command": "On", "Rssi numeric": 5},
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
calls = []
|
||||
|
||||
@callback
|
||||
def record_event(event):
|
||||
"""Add recorded event to set."""
|
||||
calls.append(event)
|
||||
|
||||
hass.bus.async_listen("signal_received", record_event)
|
||||
|
||||
await _signal_event(hass, "0a520802060101ff0f0269")
|
||||
assert len(calls) == 5
|
||||
assert any(
|
||||
call.data
|
||||
== {"entity_id": "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature"}
|
||||
for call in calls
|
||||
)
|
||||
{
|
||||
"packet_type": 22,
|
||||
"sub_type": 0,
|
||||
"type_string": "Byron SX",
|
||||
"id_string": "00:90",
|
||||
"data": "0716000100900970",
|
||||
"values": {"Sound": 9, "Battery numeric": 0, "Rssi numeric": 7},
|
||||
},
|
||||
]
|
||||
@@ -158,6 +158,7 @@ async def test_discover_light(hass, rfxtrx):
|
||||
{"rfxtrx": {"device": "abcd", "dummy": True, "automatic_add": True}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
await _signal_event(hass, "0b11009e00e6116202020070")
|
||||
state = hass.states.get("light.ac_0e61162_2")
|
||||
|
||||
@@ -105,8 +105,8 @@ async def test_several_sensors(hass, rfxtrx):
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature")
|
||||
assert state
|
||||
@@ -144,6 +144,7 @@ async def test_discover_sensor(hass, rfxtrx):
|
||||
{"rfxtrx": {"device": "abcd", "dummy": True, "automatic_add": True}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
# 1
|
||||
await _signal_event(hass, "0a520801070100b81b0279")
|
||||
@@ -252,6 +253,7 @@ async def test_update_of_sensors(hass, rfxtrx):
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature")
|
||||
assert state
|
||||
|
||||
@@ -117,6 +117,7 @@ async def test_discover_switch(hass, rfxtrx):
|
||||
{"rfxtrx": {"device": "abcd", "dummy": True, "automatic_add": True}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
await _signal_event(hass, "0b1100100118cdea02010f70")
|
||||
state = hass.states.get("switch.ac_118cdea_2")
|
||||
|
||||
Reference in new issue
Block a user