Implement config and option flow for rfxtrx integration (#39117)
* Create option flow for Rfxtrx integration (#37982) * Implement config flow for rfxtrx integration (#39299) * Add config flow * Add strings * Add first series of tests * Add tests * Adjust tests according review comments * Adjust strings * Add executor for testing connection * Change ports to dict * Fix pylint issue * Adjust tests * Migrate config entry for rfxtrx integration (#39528) * Add rfxtrx device connection validation when importing (#39582) * Implement import connection validation * Fix binary sensor tests * Move rfxtrx data * Fix cover tests * Fix test init * Fix light tests * Fix sensor tests * Fix switch tests * Refactor rfxtrx test data * Fix strings * Fix check * Rework device string in test code * Add option to delete multiple rfxtrx devices (#39625) * Opt to remove multiple devices * Fix devices key * Add tests (phase 1) * Add tests (phase 2) * Tweak remove devices test * Implement device migration function in rfxtrx option flow (#39694) * Prompt option to replace device * Revert unwanted changes * Add replace device function * WIP replace entities * Remove device/entities and update config entry * Fix styling * Add info * Add test * Fix strings * Refactor building migration map * Allow migration for all device types * Add test to migrate control device * Fixup some names * Fixup entry names in test code * Bump pyRFXtrx to 0.26 and deprecate debug config key (#40679) * Create option flow for Rfxtrx integration (#37982) * Implement config flow for rfxtrx integration (#39299) * Add config flow * Add strings * Add first series of tests * Add tests * Adjust tests according review comments * Adjust strings * Add executor for testing connection * Change ports to dict * Fix pylint issue * Adjust tests * Migrate config entry for rfxtrx integration (#39528) * Add rfxtrx device connection validation when importing (#39582) * Implement import connection validation * Fix binary sensor tests * Move rfxtrx data * Fix cover tests * Fix test init * Fix light tests * Fix sensor tests * Fix switch tests * Refactor rfxtrx test data * Fix strings * Fix check * Rework device string in test code * Add option to delete multiple rfxtrx devices (#39625) * Opt to remove multiple devices * Fix devices key * Add tests (phase 1) * Add tests (phase 2) * Tweak remove devices test * Implement device migration function in rfxtrx option flow (#39694) * Prompt option to replace device * Revert unwanted changes * Add replace device function * WIP replace entities * Remove device/entities and update config entry * Fix styling * Add info * Add test * Fix strings * Refactor building migration map * Allow migration for all device types * Add test to migrate control device * Fixup some names * Fixup entry names in test code * Bump version number * Remove debug key from connect * Remove debug option from config flow * Remove debug from tests * Fix event test * Add cv.deprecated * Fix test * Fix config schema * Add timeout on connection * Rework config schema * Fix schema...again * Prevent creation of duplicate device in rfxtrx option flow (#40656)
This commit is contained in:
1 parent
44e5ec58b0
commit
c5041b41c8
22 files changed
+2202
-363
No files matched your search
@@ -4,11 +4,23 @@ from datetime import timedelta
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import rfxtrx
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
def create_rfx_test_cfg(device="abcd", automatic_add=False, devices=None):
|
||||
"""Create rfxtrx config entry data."""
|
||||
return {
|
||||
"device": device,
|
||||
"host": None,
|
||||
"port": None,
|
||||
"automatic_add": automatic_add,
|
||||
"debug": False,
|
||||
"devices": devices,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="rfxtrx")
|
||||
@@ -37,12 +49,12 @@ async def rfxtrx_fixture(hass):
|
||||
@pytest.fixture(name="rfxtrx_automatic")
|
||||
async def rfxtrx_automatic_fixture(hass, rfxtrx):
|
||||
"""Fixture that starts up with automatic additions."""
|
||||
entry_data = create_rfx_test_cfg(automatic_add=True, devices={})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "automatic_add": True}},
|
||||
)
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
yield rfxtrx
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
"""The tests for the Rfxtrx sensor platform."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.components.rfxtrx.const import ATTR_EVENT
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.common import MockConfigEntry, mock_restore_cache
|
||||
from tests.components.rfxtrx.conftest import create_rfx_test_cfg
|
||||
|
||||
EVENT_SMOKE_DETECTOR_PANIC = "08200300a109000670"
|
||||
EVENT_SMOKE_DETECTOR_NO_PANIC = "08200300a109000770"
|
||||
@@ -21,11 +22,12 @@ EVENT_AC_118CDEA_2_ON = "0b1100100118cdea02010f70"
|
||||
|
||||
async def test_one(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f230010f71": {}}}},
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={"0b1100cd0213c7f230010f71": {}})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.ac_213c7f2_48")
|
||||
@@ -36,22 +38,20 @@ async def test_one(hass, rfxtrx):
|
||||
|
||||
async def test_one_pt2262(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0913000022670e013970": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0913000022670e013970": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -71,19 +71,14 @@ async def test_one_pt2262(hass, rfxtrx):
|
||||
|
||||
async def test_pt2262_unconfigured(hass, rfxtrx):
|
||||
"""Test with discovery for PT2262."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0913000022670e013970": {},
|
||||
"09130000226707013970": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0913000022670e013970": {}, "09130000226707013970": {}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -109,11 +104,12 @@ async def test_state_restore(hass, rfxtrx, state, event):
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state, attributes={ATTR_EVENT: event})])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f230010f71": {}}}},
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={"0b1100cd0213c7f230010f71": {}})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
@@ -121,20 +117,18 @@ async def test_state_restore(hass, rfxtrx, state, event):
|
||||
|
||||
async def test_several(hass, rfxtrx):
|
||||
"""Test with 3."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230010f71": {},
|
||||
"0b1100100118cdea02010f70": {},
|
||||
"0b1100101118cdea02010f70": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0b1100cd0213c7f230010f71": {},
|
||||
"0b1100100118cdea02010f70": {},
|
||||
"0b1100101118cdea02010f70": {},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.ac_213c7f2_48")
|
||||
@@ -181,16 +175,12 @@ async def test_off_delay_restore(hass, rfxtrx):
|
||||
],
|
||||
)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {EVENT_AC_118CDEA_2_ON: {"off_delay": 5}},
|
||||
}
|
||||
},
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={EVENT_AC_118CDEA_2_ON: {"off_delay": 5}})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -201,16 +191,14 @@ async def test_off_delay_restore(hass, rfxtrx):
|
||||
|
||||
async def test_off_delay(hass, rfxtrx, timestep):
|
||||
"""Test with discovery."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {"0b1100100118cdea02010f70": {"off_delay": 5}},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1100100118cdea02010f70": {"off_delay": 5}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -295,27 +283,25 @@ async def test_light(hass, rfxtrx_automatic):
|
||||
|
||||
async def test_pt2262_duplicate_id(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0913000022670e013970": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
},
|
||||
"09130000226707013970": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0913000022670e013970": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
},
|
||||
"09130000226707013970": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -3,19 +3,23 @@ from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.common import MockConfigEntry, mock_restore_cache
|
||||
from tests.components.rfxtrx.conftest import create_rfx_test_cfg
|
||||
|
||||
|
||||
async def test_one_cover(hass, rfxtrx):
|
||||
"""Test with 1 cover."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1400cd0213c7f20d010f51": {}}}},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1400cd0213c7f20d010f51": {"signal_repetitions": 1}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
||||
@@ -57,11 +61,14 @@ async def test_state_restore(hass, rfxtrx, state):
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state)])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1400cd0213c7f20d010f51": {}}}},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1400cd0213c7f20d010f51": {"signal_repetitions": 1}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
@@ -69,20 +76,18 @@ async def test_state_restore(hass, rfxtrx, state):
|
||||
|
||||
async def test_several_covers(hass, rfxtrx):
|
||||
"""Test with 3 covers."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0b1400cd0213c7f20d010f51": {},
|
||||
"0A1400ADF394AB010D0060": {},
|
||||
"09190000009ba8010100": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0b1400cd0213c7f20d010f51": {"signal_repetitions": 1},
|
||||
"0A1400ADF394AB010D0060": {"signal_repetitions": 1},
|
||||
"09190000009ba8010100": {"signal_repetitions": 1},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
||||
@@ -118,19 +123,17 @@ async def test_discover_covers(hass, rfxtrx_automatic):
|
||||
|
||||
async def test_duplicate_cover(hass, rfxtrx):
|
||||
"""Test with 2 duplicate covers."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0b1400cd0213c7f20d010f51": {},
|
||||
"0b1400cd0213c7f20d010f50": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0b1400cd0213c7f20d010f51": {"signal_repetitions": 1},
|
||||
"0b1400cd0213c7f20d010f50": {"signal_repetitions": 1},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
"""The tests for the Rfxtrx component."""
|
||||
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.components.rfxtrx.const import EVENT_RFXTRX_EVENT
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import call
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.rfxtrx.conftest import create_rfx_test_cfg
|
||||
|
||||
|
||||
async def test_valid_config(hass):
|
||||
@@ -55,21 +58,19 @@ async def test_invalid_config(hass):
|
||||
|
||||
async def test_fire_event(hass, rfxtrx):
|
||||
"""Test fire event."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "/dev/serial/by-id/usb"
|
||||
+ "-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
||||
"automatic_add": True,
|
||||
"devices": {
|
||||
"0b1100cd0213c7f210010f51": {"fire_event": True},
|
||||
"0716000100900970": {"fire_event": True},
|
||||
},
|
||||
}
|
||||
entry_data = create_rfx_test_cfg(
|
||||
device="/dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0",
|
||||
automatic_add=True,
|
||||
devices={
|
||||
"0b1100cd0213c7f210010f51": {"fire_event": True},
|
||||
"0716000100900970": {"fire_event": True},
|
||||
},
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -101,16 +102,19 @@ async def test_fire_event(hass, rfxtrx):
|
||||
"type_string": "Byron SX",
|
||||
"id_string": "00:90",
|
||||
"data": "0716000100900970",
|
||||
"values": {"Sound": 9, "Battery numeric": 0, "Rssi numeric": 7},
|
||||
"values": {"Command": "Chime", "Rssi numeric": 7, "Sound": 9},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
async def test_send(hass, rfxtrx):
|
||||
"""Test configuration."""
|
||||
assert await async_setup_component(
|
||||
hass, "rfxtrx", {"rfxtrx": {"device": "/dev/null"}}
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(device="/dev/null", devices={})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
|
||||
@@ -4,19 +4,23 @@ from unittest.mock import call
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.common import MockConfigEntry, mock_restore_cache
|
||||
from tests.components.rfxtrx.conftest import create_rfx_test_cfg
|
||||
|
||||
|
||||
async def test_one_light(hass, rfxtrx):
|
||||
"""Test with 1 light."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f210020f51": {}}}},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1100cd0213c7f210020f51": {"signal_repetitions": 1}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.ac_213c7f2_16")
|
||||
@@ -95,11 +99,14 @@ async def test_state_restore(hass, rfxtrx, state, brightness):
|
||||
hass, [State(entity_id, state, attributes={ATTR_BRIGHTNESS: brightness})]
|
||||
)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f210020f51": {}}}},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1100cd0213c7f210020f51": {"signal_repetitions": 1}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
@@ -108,20 +115,18 @@ async def test_state_restore(hass, rfxtrx, state, brightness):
|
||||
|
||||
async def test_several_lights(hass, rfxtrx):
|
||||
"""Test with 3 lights."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230020f71": {},
|
||||
"0b1100100118cdea02020f70": {},
|
||||
"0b1100101118cdea02050f70": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0b1100cd0213c7f230020f71": {"signal_repetitions": 1},
|
||||
"0b1100100118cdea02020f70": {"signal_repetitions": 1},
|
||||
"0b1100101118cdea02050f70": {"signal_repetitions": 1},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -160,18 +165,14 @@ async def test_several_lights(hass, rfxtrx):
|
||||
@pytest.mark.parametrize("repetitions", [1, 3])
|
||||
async def test_repetitions(hass, rfxtrx, repetitions):
|
||||
"""Test signal repetitions."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230020f71": {"signal_repetitions": repetitions}
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1100cd0213c7f230020f71": {"signal_repetitions": repetitions}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
"""The tests for the Rfxtrx sensor platform."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.components.rfxtrx.const import ATTR_EVENT
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, TEMP_CELSIUS
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.common import MockConfigEntry, mock_restore_cache
|
||||
from tests.components.rfxtrx.conftest import create_rfx_test_cfg
|
||||
|
||||
|
||||
async def test_default_config(hass, rfxtrx):
|
||||
"""Test with 0 sensor."""
|
||||
await async_setup_component(
|
||||
hass, "sensor", {"sensor": {"platform": "rfxtrx", "devices": {}}}
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
@@ -21,11 +25,12 @@ async def test_default_config(hass, rfxtrx):
|
||||
|
||||
async def test_one_sensor(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0a52080705020095220269": {}}}},
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={"0a52080705020095220269": {}})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature")
|
||||
@@ -49,11 +54,12 @@ async def test_state_restore(hass, rfxtrx, state, event):
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state, attributes={ATTR_EVENT: event})])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0a520801070100b81b0279": {}}}},
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={"0a520801070100b81b0279": {}})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
@@ -61,11 +67,12 @@ async def test_state_restore(hass, rfxtrx, state, event):
|
||||
|
||||
async def test_one_sensor_no_datatype(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0a52080705020095220269": {}}}},
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={"0a52080705020095220269": {}})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
base_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02"
|
||||
@@ -104,19 +111,17 @@ async def test_one_sensor_no_datatype(hass, rfxtrx):
|
||||
|
||||
async def test_several_sensors(hass, rfxtrx):
|
||||
"""Test with 3 sensors."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0a52080705020095220269": {},
|
||||
"0a520802060100ff0e0269": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0a52080705020095220269": {},
|
||||
"0a520802060100ff0e0269": {},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -244,19 +249,17 @@ async def test_discover_sensor(hass, rfxtrx_automatic):
|
||||
|
||||
async def test_update_of_sensors(hass, rfxtrx):
|
||||
"""Test with 3 sensors."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0a52080705020095220269": {},
|
||||
"0a520802060100ff0e0269": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0a52080705020095220269": {},
|
||||
"0a520802060100ff0e0269": {},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
@@ -290,23 +293,21 @@ async def test_update_of_sensors(hass, rfxtrx):
|
||||
|
||||
async def test_rssi_sensor(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0913000022670e013b70": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
},
|
||||
"0b1100cd0213c7f230010f71": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0913000022670e013b70": {
|
||||
"data_bits": 4,
|
||||
"command_on": 0xE,
|
||||
"command_off": 0x7,
|
||||
},
|
||||
"0b1100cd0213c7f230010f71": {},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import pytest
|
||||
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.core import State
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_restore_cache
|
||||
from tests.common import MockConfigEntry, mock_restore_cache
|
||||
from tests.components.rfxtrx.conftest import create_rfx_test_cfg
|
||||
|
||||
EVENT_RFY_ENABLE_SUN_AUTO = "081a00000301010113"
|
||||
EVENT_RFY_DISABLE_SUN_AUTO = "081a00000301010114"
|
||||
@@ -15,11 +15,14 @@ EVENT_RFY_DISABLE_SUN_AUTO = "081a00000301010114"
|
||||
|
||||
async def test_one_switch(hass, rfxtrx):
|
||||
"""Test with 1 switch."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f210010f51": {}}}},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1100cd0213c7f210010f51": {"signal_repetitions": 1}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("switch.ac_213c7f2_16")
|
||||
@@ -55,11 +58,14 @@ async def test_state_restore(hass, rfxtrx, state):
|
||||
|
||||
mock_restore_cache(hass, [State(entity_id, state)])
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "devices": {"0b1100cd0213c7f210010f51": {}}}},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1100cd0213c7f210010f51": {"signal_repetitions": 1}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(entity_id).state == state
|
||||
@@ -67,20 +73,18 @@ async def test_state_restore(hass, rfxtrx, state):
|
||||
|
||||
async def test_several_switches(hass, rfxtrx):
|
||||
"""Test with 3 switches."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230010f71": {},
|
||||
"0b1100100118cdea02010f70": {},
|
||||
"0b1100101118cdea02010f70": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={
|
||||
"0b1100cd0213c7f230010f71": {"signal_repetitions": 1},
|
||||
"0b1100100118cdea02010f70": {"signal_repetitions": 1},
|
||||
"0b1100101118cdea02010f70": {"signal_repetitions": 1},
|
||||
}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("switch.ac_213c7f2_48")
|
||||
@@ -102,18 +106,14 @@ async def test_several_switches(hass, rfxtrx):
|
||||
@pytest.mark.parametrize("repetitions", [1, 3])
|
||||
async def test_repetitions(hass, rfxtrx, repetitions):
|
||||
"""Test signal repetitions."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {
|
||||
"0b1100cd0213c7f230010f71": {"signal_repetitions": repetitions}
|
||||
},
|
||||
}
|
||||
},
|
||||
entry_data = create_rfx_test_cfg(
|
||||
devices={"0b1100cd0213c7f230010f71": {"signal_repetitions": repetitions}}
|
||||
)
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
@@ -156,16 +156,12 @@ async def test_discover_rfy_sun_switch(hass, rfxtrx_automatic):
|
||||
|
||||
async def test_unknown_event_code(hass, rfxtrx):
|
||||
"""Test with 3 switches."""
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {"1234567890": {}},
|
||||
}
|
||||
},
|
||||
)
|
||||
entry_data = create_rfx_test_cfg(devices={"1234567890": {"signal_repetitions": 1}})
|
||||
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
conf_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
Reference in new issue
Block a user