Add system options to config entries (#25926)
* Add system options to config entries * For feedback * Follow most of balloobs comments * Fix balloobs comments * Improvements * Fix second round of Balloobs comments * Fix third round * Add system options to mock config entry * Fix integration tests * Fix the last failing tests * Fix disabled string * Fix failing disabled_by tests * New tests * Config entry WS API tests * Fix comments
This commit is contained in:
1 parent
fc716a45c9
commit
a2589f56e1
29 files changed
+254
-27
No files matched your search
@@ -57,6 +57,7 @@ async def setup_device(hass):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
options=ENTRY_OPTIONS,
|
||||
)
|
||||
device = axis.AxisNetworkDevice(hass, config_entry)
|
||||
|
||||
@@ -41,6 +41,7 @@ async def setup_device(hass):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
options=ENTRY_OPTIONS,
|
||||
)
|
||||
device = axis.AxisNetworkDevice(hass, config_entry)
|
||||
|
||||
@@ -59,6 +59,7 @@ async def setup_device(hass):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
options=ENTRY_OPTIONS,
|
||||
)
|
||||
device = axis.AxisNetworkDevice(hass, config_entry)
|
||||
|
||||
@@ -584,3 +584,47 @@ async def test_two_step_options_flow(hass, client):
|
||||
"description": None,
|
||||
"description_placeholders": None,
|
||||
}
|
||||
|
||||
|
||||
async def test_list_system_options(hass, hass_ws_client):
|
||||
"""Test that we can list an entries system options."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
entry = MockConfigEntry(domain="demo")
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await ws_client.send_json(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "config_entries/system_options/list",
|
||||
"entry_id": entry.entry_id,
|
||||
}
|
||||
)
|
||||
response = await ws_client.receive_json()
|
||||
|
||||
assert response["success"]
|
||||
assert response["result"] == {"disable_new_entities": False}
|
||||
|
||||
|
||||
async def test_update_system_options(hass, hass_ws_client):
|
||||
"""Test that we can update system options."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
ws_client = await hass_ws_client(hass)
|
||||
|
||||
entry = MockConfigEntry(domain="demo")
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await ws_client.send_json(
|
||||
{
|
||||
"id": 5,
|
||||
"type": "config_entries/system_options/update",
|
||||
"entry_id": entry.entry_id,
|
||||
"disable_new_entities": True,
|
||||
}
|
||||
)
|
||||
response = await ws_client.receive_json()
|
||||
|
||||
assert response["success"]
|
||||
assert response["result"]["disable_new_entities"]
|
||||
assert entry.system_options.disable_new_entities
|
||||
@@ -59,7 +59,8 @@ async def setup_gateway(hass, data, allow_clip_sensor=True):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
ENTRY_OPTIONS,
|
||||
system_options={},
|
||||
options=ENTRY_OPTIONS,
|
||||
)
|
||||
gateway = deconz.DeconzGateway(hass, config_entry)
|
||||
gateway.api = DeconzSession(loop, session, **config_entry.data)
|
||||
|
||||
@@ -71,7 +71,8 @@ async def setup_gateway(hass, data, allow_clip_sensor=True):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
ENTRY_OPTIONS,
|
||||
system_options={},
|
||||
options=ENTRY_OPTIONS,
|
||||
)
|
||||
gateway = deconz.DeconzGateway(hass, config_entry)
|
||||
gateway.api = DeconzSession(hass.loop, session, **config_entry.data)
|
||||
|
||||
@@ -63,6 +63,7 @@ async def setup_gateway(hass, data):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
)
|
||||
gateway = deconz.DeconzGateway(hass, config_entry)
|
||||
gateway.api = DeconzSession(loop, session, **config_entry.data)
|
||||
|
||||
@@ -90,7 +90,8 @@ async def setup_gateway(hass, data, allow_deconz_groups=True):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
ENTRY_OPTIONS,
|
||||
system_options={},
|
||||
options=ENTRY_OPTIONS,
|
||||
)
|
||||
gateway = deconz.DeconzGateway(hass, config_entry)
|
||||
gateway.api = DeconzSession(loop, session, **config_entry.data)
|
||||
|
||||
@@ -46,6 +46,7 @@ async def setup_gateway(hass, data):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
)
|
||||
gateway = deconz.DeconzGateway(hass, config_entry)
|
||||
gateway.api = DeconzSession(loop, session, **config_entry.data)
|
||||
|
||||
@@ -103,7 +103,8 @@ async def setup_gateway(hass, data, allow_clip_sensor=True):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
ENTRY_OPTIONS,
|
||||
system_options={},
|
||||
options=ENTRY_OPTIONS,
|
||||
)
|
||||
gateway = deconz.DeconzGateway(hass, config_entry)
|
||||
gateway.api = DeconzSession(loop, session, **config_entry.data)
|
||||
|
||||
@@ -67,6 +67,7 @@ async def setup_gateway(hass, data):
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
)
|
||||
gateway = deconz.DeconzGateway(hass, config_entry)
|
||||
gateway.api = DeconzSession(loop, session, **config_entry.data)
|
||||
|
||||
@@ -97,6 +97,7 @@ async def test_storage_is_removed_on_config_entry_removal(hass, utcnow):
|
||||
pairing_data,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
)
|
||||
|
||||
assert hkid in hass.data[ENTITY_MAP].storage_data
|
||||
|
||||
@@ -221,6 +221,7 @@ async def setup_bridge(hass, mock_bridge):
|
||||
{"host": "mock-host"},
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
system_options={},
|
||||
)
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, "light")
|
||||
# To flush out the service call to update the group
|
||||
|
||||
@@ -306,6 +306,7 @@ async def setup_bridge(hass, mock_bridge, hostname=None):
|
||||
{"host": hostname},
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
system_options={},
|
||||
)
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, "binary_sensor")
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, "sensor")
|
||||
|
||||
@@ -142,7 +142,7 @@ async def test_config_flow_entry_migrate(hass):
|
||||
"media_player",
|
||||
"ps4",
|
||||
MOCK_UNIQUE_ID,
|
||||
config_entry_id=MOCK_ENTRY_ID,
|
||||
config_entry=mock_entry,
|
||||
device_id=MOCK_DEVICE_ID,
|
||||
)
|
||||
assert len(mock_e_registry.entities) == 1
|
||||
|
||||
@@ -335,7 +335,7 @@ async def test_device_info_is_assummed(hass):
|
||||
mock_unique_id = ps4.format_unique_id(MOCK_CREDS, MOCK_HOST_ID)
|
||||
mock_e_registry = mock_registry(hass)
|
||||
mock_e_registry.async_get_or_create(
|
||||
"media_player", DOMAIN, mock_unique_id, config_entry_id=MOCK_ENTRY_ID
|
||||
"media_player", DOMAIN, mock_unique_id, config_entry=MOCK_CONFIG
|
||||
)
|
||||
mock_entity_id = mock_e_registry.async_get_entity_id(
|
||||
"media_player", DOMAIN, mock_unique_id
|
||||
|
||||
@@ -56,6 +56,7 @@ async def setup_platform(hass, platform: str, *, devices=None, scenes=None):
|
||||
{CONF_INSTALLED_APP_ID: str(uuid4())},
|
||||
SOURCE_USER,
|
||||
CONN_CLASS_CLOUD_PUSH,
|
||||
system_options={},
|
||||
)
|
||||
broker = DeviceBroker(
|
||||
hass, config_entry, Mock(), Mock(), devices or [], scenes or []
|
||||
|
||||
@@ -145,6 +145,7 @@ async def setup_controller(hass, mock_controller):
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
entry_id=1,
|
||||
system_options={},
|
||||
)
|
||||
mock_controller.config_entry = config_entry
|
||||
|
||||
@@ -235,20 +236,31 @@ async def test_restoring_client(hass, mock_controller):
|
||||
mock_controller.mock_client_all_responses.append([CLIENT_1])
|
||||
mock_controller.unifi_config = {unifi.CONF_BLOCK_CLIENT: True}
|
||||
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
1,
|
||||
unifi.DOMAIN,
|
||||
"Mock Title",
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
entry_id=1,
|
||||
system_options={},
|
||||
)
|
||||
|
||||
registry = await entity_registry.async_get_registry(hass)
|
||||
registry.async_get_or_create(
|
||||
device_tracker.DOMAIN,
|
||||
unifi_dt.UNIFI_DOMAIN,
|
||||
"{}-mock-site".format(CLIENT_1["mac"]),
|
||||
suggested_object_id=CLIENT_1["hostname"],
|
||||
config_entry_id=1,
|
||||
config_entry=config_entry,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
device_tracker.DOMAIN,
|
||||
unifi_dt.UNIFI_DOMAIN,
|
||||
"{}-mock-site".format(CLIENT_2["mac"]),
|
||||
suggested_object_id=CLIENT_2["hostname"],
|
||||
config_entry_id=1,
|
||||
config_entry=config_entry,
|
||||
)
|
||||
|
||||
await setup_controller(hass, mock_controller)
|
||||
|
||||
@@ -262,6 +262,7 @@ async def setup_controller(hass, mock_controller):
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
entry_id=1,
|
||||
system_options={},
|
||||
)
|
||||
mock_controller.config_entry = config_entry
|
||||
|
||||
@@ -468,20 +469,31 @@ async def test_restoring_client(hass, mock_controller):
|
||||
mock_controller.mock_client_all_responses.append([CLIENT_1])
|
||||
mock_controller.unifi_config = {unifi.CONF_BLOCK_CLIENT: ["random mac"]}
|
||||
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
1,
|
||||
unifi.DOMAIN,
|
||||
"Mock Title",
|
||||
ENTRY_CONFIG,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_POLL,
|
||||
entry_id=1,
|
||||
system_options={},
|
||||
)
|
||||
|
||||
registry = await entity_registry.async_get_registry(hass)
|
||||
registry.async_get_or_create(
|
||||
switch.DOMAIN,
|
||||
unifi.DOMAIN,
|
||||
"poe-{}".format(CLIENT_1["mac"]),
|
||||
suggested_object_id=CLIENT_1["hostname"],
|
||||
config_entry_id=1,
|
||||
config_entry=config_entry,
|
||||
)
|
||||
registry.async_get_or_create(
|
||||
switch.DOMAIN,
|
||||
unifi.DOMAIN,
|
||||
"poe-{}".format(CLIENT_2["mac"]),
|
||||
suggested_object_id=CLIENT_2["hostname"],
|
||||
config_entry_id=1,
|
||||
config_entry=config_entry,
|
||||
)
|
||||
|
||||
await setup_controller(hass, mock_controller)
|
||||
|
||||
@@ -14,7 +14,13 @@ from homeassistant.components.zha.core.store import async_get_registry
|
||||
def config_entry_fixture(hass):
|
||||
"""Fixture representing a config entry."""
|
||||
config_entry = config_entries.ConfigEntry(
|
||||
1, DOMAIN, "Mock Title", {}, "test", config_entries.CONN_CLASS_LOCAL_PUSH
|
||||
1,
|
||||
DOMAIN,
|
||||
"Mock Title",
|
||||
{},
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
)
|
||||
return config_entry
|
||||
|
||||
|
||||
@@ -287,6 +287,7 @@ async def setup_ozw(hass, mock_openzwave):
|
||||
{"usb_path": "mock-path", "network_key": "mock-key"},
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
system_options={},
|
||||
)
|
||||
await hass.config_entries.async_forward_entry_setup(config_entry, "lock")
|
||||
await hass.async_block_till_done()
|
||||
|
||||
Reference in new issue
Block a user