response
stringlengths 1
33.1k
| instruction
stringlengths 22
582k
|
---|---|
Create a mock GreenEye Monitor. | def mock_monitor(serial_number: int) -> MagicMock:
"""Create a mock GreenEye Monitor."""
monitor = mock_with_listeners()
monitor.serial_number = serial_number
monitor.voltage_sensor = mock_voltage_sensor()
monitor.pulse_counters = [mock_pulse_counter() for i in range(4)]
monitor.temperature_sensors = [mock_temperature_sensor() for i in range(8)]
monitor.channels = [mock_channel() for i in range(32)]
return monitor |
Assert that the given entity has the expected state and at least the provided attributes. | def assert_sensor_state(
hass: HomeAssistant,
entity_id: str,
expected_state: str,
attributes: dict[str, Any] = {},
) -> None:
"""Assert that the given entity has the expected state and at least the provided attributes."""
state = hass.states.get(entity_id)
assert state
actual_state = state.state
assert actual_state == expected_state
for key, value in attributes.items():
assert key in state.attributes
assert state.attributes[key] == value |
Assert that a temperature sensor entity was registered properly. | def assert_temperature_sensor_registered(
hass: HomeAssistant,
serial_number: int,
number: int,
name: str,
):
"""Assert that a temperature sensor entity was registered properly."""
sensor = assert_sensor_registered(hass, serial_number, "temp", number, name)
assert sensor.original_device_class is SensorDeviceClass.TEMPERATURE |
Assert that a pulse counter entity was registered properly. | def assert_pulse_counter_registered(
hass: HomeAssistant,
serial_number: int,
number: int,
name: str,
quantity: str,
per_time: str,
):
"""Assert that a pulse counter entity was registered properly."""
sensor = assert_sensor_registered(hass, serial_number, "pulse", number, name)
assert sensor.unit_of_measurement == f"{quantity}/{per_time}" |
Assert that a power sensor entity was registered properly. | def assert_power_sensor_registered(
hass: HomeAssistant, serial_number: int, number: int, name: str
) -> None:
"""Assert that a power sensor entity was registered properly."""
sensor = assert_sensor_registered(hass, serial_number, "current", number, name)
assert sensor.unit_of_measurement == UnitOfPower.WATT
assert sensor.original_device_class is SensorDeviceClass.POWER |
Assert that a voltage sensor entity was registered properly. | def assert_voltage_sensor_registered(
hass: HomeAssistant, serial_number: int, number: int, name: str
) -> None:
"""Assert that a voltage sensor entity was registered properly."""
sensor = assert_sensor_registered(hass, serial_number, "volts", number, name)
assert sensor.unit_of_measurement == UnitOfElectricPotential.VOLT
assert sensor.original_device_class is SensorDeviceClass.VOLTAGE |
Assert that a sensor entity of a given type was registered properly. | def assert_sensor_registered(
hass: HomeAssistant,
serial_number: int,
sensor_type: str,
number: int,
name: str,
) -> RegistryEntry:
"""Assert that a sensor entity of a given type was registered properly."""
registry = get_entity_registry(hass)
unique_id = f"{serial_number}-{sensor_type}-{number}"
entity_id = registry.async_get_entity_id("sensor", DOMAIN, unique_id)
assert entity_id is not None
sensor = registry.async_get(entity_id)
assert sensor
assert sensor.unique_id == unique_id
assert sensor.original_name == name
return sensor |
Provide a mock greeneye.Monitors object that has listeners and can add new monitors. | def monitors() -> Generator[AsyncMock, None, None]:
"""Provide a mock greeneye.Monitors object that has listeners and can add new monitors."""
with patch("greeneye.Monitors", autospec=True) as mock_monitors:
mock = mock_monitors.return_value
add_listeners(mock)
mock.monitors = {}
def add_monitor(monitor: MagicMock) -> None:
"""Add the given mock monitor as a monitor with the given serial number, notifying any listeners on the Monitors object."""
serial_number = monitor.serial_number
mock.monitors[serial_number] = monitor
mock.notify_all_listeners(monitor)
mock.add_monitor = add_monitor
yield mock |
Reload the automation from config. | def reload(hass):
"""Reload the automation from config."""
hass.add_job(async_reload, hass) |
Reload the automation from config. | def async_reload(hass):
"""Reload the automation from config."""
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_RELOAD)) |
Create/Update a group. | def set_group(
hass,
object_id,
name=None,
entity_ids=None,
icon=None,
add=None,
):
"""Create/Update a group."""
hass.add_job(
async_set_group,
hass,
object_id,
name,
entity_ids,
icon,
add,
) |
Create/Update a group. | def async_set_group(
hass,
object_id,
name=None,
entity_ids=None,
icon=None,
add=None,
):
"""Create/Update a group."""
data = {
key: value
for key, value in [
(ATTR_OBJECT_ID, object_id),
(ATTR_NAME, name),
(ATTR_ENTITIES, entity_ids),
(ATTR_ICON, icon),
(ATTR_ADD_ENTITIES, add),
]
if value is not None
}
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SET, data)) |
Remove a user group. | def async_remove(hass, object_id):
"""Remove a user group."""
data = {ATTR_OBJECT_ID: object_id}
hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_REMOVE, data)) |
Get suggested value for key in voluptuous schema. | def get_suggested(schema, key):
"""Get suggested value for key in voluptuous schema."""
for k in schema:
if k == key:
if k.description is None or "suggested_value" not in k.description:
return None
return k.description["suggested_value"]
# Wanted key absent from schema
raise Exception |
Mock demo YouTube player media seek. | def media_player_media_seek_fixture():
"""Mock demo YouTube player media seek."""
with patch(
"homeassistant.components.demo.media_player.DemoYoutubePlayer.media_seek",
autospec=True,
) as seek:
yield seek |
Specialize the mock platform for legacy notify service. | def mock_notify_platform(
hass: HomeAssistant,
tmp_path: Path,
async_get_service: Any = None,
):
"""Specialize the mock platform for legacy notify service."""
loaded_platform = MockNotifyPlatform(async_get_service)
mock_platform(hass, "test.notify", loaded_platform)
return loaded_platform |
Override async_setup_entry. | def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.guardian.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry |
Define a config entry fixture. | def config_entry_fixture(hass, config, unique_id):
"""Define a config entry fixture."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id=unique_id,
data={CONF_UID: "3456", **config},
)
entry.add_to_hass(hass)
return entry |
Define a config entry data fixture. | def config_fixture(hass):
"""Define a config entry data fixture."""
return {
CONF_IP_ADDRESS: "192.168.1.100",
CONF_PORT: 7777,
} |
Define data from a successful sensor_pair_dump response. | def data_sensor_pair_dump_fixture():
"""Define data from a successful sensor_pair_dump response."""
return json.loads(load_fixture("sensor_pair_dump_data.json", "guardian")) |
Define data from a successful sensor_pair_sensor response. | def data_sensor_pair_sensor_fixture():
"""Define data from a successful sensor_pair_sensor response."""
return json.loads(load_fixture("sensor_pair_sensor_data.json", "guardian")) |
Define data from a successful sensor_paired_sensor_status response. | def data_sensor_paired_sensor_status_fixture():
"""Define data from a successful sensor_paired_sensor_status response."""
return json.loads(load_fixture("sensor_paired_sensor_status_data.json", "guardian")) |
Define data from a successful system_diagnostics response. | def data_system_diagnostics_fixture():
"""Define data from a successful system_diagnostics response."""
return json.loads(load_fixture("system_diagnostics_data.json", "guardian")) |
Define data from a successful system_onboard_sensor_status response. | def data_system_onboard_sensor_status_fixture():
"""Define data from a successful system_onboard_sensor_status response."""
return json.loads(
load_fixture("system_onboard_sensor_status_data.json", "guardian")
) |
Define data from a successful system_ping response. | def data_system_ping_fixture():
"""Define data from a successful system_ping response."""
return json.loads(load_fixture("system_ping_data.json", "guardian")) |
Define data from a successful valve_status response. | def data_valve_status_fixture():
"""Define data from a successful valve_status response."""
return json.loads(load_fixture("valve_status_data.json", "guardian")) |
Define data from a successful wifi_status response. | def data_wifi_status_fixture():
"""Define data from a successful wifi_status response."""
return json.loads(load_fixture("wifi_status_data.json", "guardian")) |
Define a config entry unique ID fixture. | def unique_id_fixture(hass):
"""Define a config entry unique ID fixture."""
return "guardian_3456" |
Disable plumbum in tests as it can cause the test suite to fail.
plumbum can leave behind PlumbumTimeoutThreads | def disable_plumbum():
"""Disable plumbum in tests as it can cause the test suite to fail.
plumbum can leave behind PlumbumTimeoutThreads
"""
with patch("plumbum.local"), patch("plumbum.colors"):
yield |
Capture api_call events. | def capture_api_call_success(hass):
"""Capture api_call events."""
return async_capture_events(hass, EVENT_API_CALL_SUCCESS) |
Test entry for the following tests. | def habitica_entry(hass):
"""Test entry for the following tests."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id="test-api-user",
data={
"api_user": "test-api-user",
"api_key": "test-api-key",
"url": DEFAULT_URL,
},
)
entry.add_to_hass(hass)
return entry |
Register requests for the tests. | def common_requests(aioclient_mock):
"""Register requests for the tests."""
aioclient_mock.get(
"https://habitica.com/api/v3/user",
json={
"data": {
"api_user": "test-api-user",
"profile": {"name": TEST_USER_NAME},
"stats": {
"class": "test-class",
"con": 1,
"exp": 2,
"gp": 3,
"hp": 4,
"int": 5,
"lvl": 6,
"maxHealth": 7,
"maxMP": 8,
"mp": 9,
"per": 10,
"points": 11,
"str": 12,
"toNextLevel": 13,
},
}
},
)
for n_tasks, task_type in enumerate(TASKS_TYPES.keys(), start=1):
aioclient_mock.get(
f"https://habitica.com/api/v3/tasks/user?type={task_type}",
json={
"data": [
{"text": f"this is a mock {task_type} #{task}", "id": f"{task}"}
for task in range(n_tasks)
]
},
)
aioclient_mock.post(
"https://habitica.com/api/v3/tasks/user",
status=HTTPStatus.CREATED,
json={"data": TEST_API_CALL_ARGS},
)
return aioclient_mock |
Create the FakeHarmonyClient instance. | def harmony_client():
"""Create the FakeHarmonyClient instance."""
return FakeHarmonyClient() |
Patch the real HarmonyClient with initialization side effect. | def mock_hc(harmony_client):
"""Patch the real HarmonyClient with initialization side effect."""
with patch(
"homeassistant.components.harmony.data.HarmonyClient",
side_effect=harmony_client.initialize,
) as fake:
yield fake |
Patches write_config_file to remove side effects. | def mock_write_config():
"""Patches write_config_file to remove side effects."""
with patch(
"homeassistant.components.harmony.remote.HarmonyRemote.write_config_file",
) as mock:
yield mock |
Return mock config entry. | def mock_config_entry() -> MockConfigEntry:
"""Return mock config entry."""
return MockConfigEntry(
domain=DOMAIN,
unique_id="123",
data={CONF_HOST: "192.0.2.0", CONF_NAME: HUB_NAME},
) |
Disable the security filter to ensure the integration is secure. | def disable_security_filter():
"""Disable the security filter to ensure the integration is secure."""
with patch(
"homeassistant.components.http.security_filter.FILTERS",
re.compile("not-matching-anything"),
):
yield |
Fixture to inject hassio env. | def hassio_env():
"""Fixture to inject hassio env."""
with (
patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}),
patch(
"homeassistant.components.hassio.HassIO.is_connected",
return_value={"result": "ok", "data": {}},
),
patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}),
patch(
"homeassistant.components.hassio.HassIO.get_info",
Mock(side_effect=HassioAPIError()),
),
):
yield |
Create mock hassio http client. | def hassio_stubs(hassio_env, hass, hass_client, aioclient_mock):
"""Create mock hassio http client."""
with (
patch(
"homeassistant.components.hassio.HassIO.update_hass_api",
return_value={"result": "ok"},
) as hass_api,
patch(
"homeassistant.components.hassio.HassIO.update_hass_timezone",
return_value={"result": "ok"},
),
patch(
"homeassistant.components.hassio.HassIO.get_info",
side_effect=HassioAPIError(),
),
patch(
"homeassistant.components.hassio.HassIO.get_ingress_panels",
return_value={"panels": []},
),
patch(
"homeassistant.components.hassio.issues.SupervisorIssues.setup",
),
patch(
"homeassistant.components.hassio.HassIO.refresh_updates",
),
):
hass.set_state(CoreState.starting)
hass.loop.run_until_complete(async_setup_component(hass, "hassio", {}))
return hass_api.call_args[0][1] |
Return a Hass.io HTTP client. | def hassio_client(hassio_stubs, hass, hass_client):
"""Return a Hass.io HTTP client."""
return hass.loop.run_until_complete(hass_client()) |
Return a Hass.io HTTP client without auth. | def hassio_noauth_client(hassio_stubs, hass, aiohttp_client):
"""Return a Hass.io HTTP client without auth."""
return hass.loop.run_until_complete(aiohttp_client(hass.http.app)) |
Mock all setup requests. | def all_setup_requests(
aioclient_mock: AiohttpClientMocker, request: pytest.FixtureRequest
):
"""Mock all setup requests."""
include_addons = hasattr(request, "param") and request.param.get(
"include_addons", False
)
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/info",
json={
"result": "ok",
"data": {
"supervisor": "222",
"homeassistant": "0.110.0",
"hassos": "1.2.3",
},
},
)
aioclient_mock.get(
"http://127.0.0.1/store",
json={
"result": "ok",
"data": {"addons": [], "repositories": []},
},
)
aioclient_mock.get(
"http://127.0.0.1/host/info",
json={
"result": "ok",
"data": {
"result": "ok",
"data": {
"chassis": "vm",
"operating_system": "Debian GNU/Linux 10 (buster)",
"kernel": "4.19.0-6-amd64",
},
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/info",
json={"result": "ok", "data": {"version_latest": "1.0.0", "version": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={
"result": "ok",
"data": {
"version_latest": "1.0.0",
"version": "1.0.0",
"update_available": False,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={
"result": "ok",
"data": {
"result": "ok",
"version": "1.0.0",
"version_latest": "1.0.0",
"auto_update": True,
"addons": [
{
"name": "test",
"slug": "test",
"update_available": False,
"version": "1.0.0",
"version_latest": "1.0.0",
"repository": "core",
"state": "started",
"icon": False,
},
{
"name": "test2",
"slug": "test2",
"update_available": False,
"version": "1.0.0",
"version_latest": "1.0.0",
"repository": "core",
"state": "started",
"icon": False,
},
]
if include_addons
else [],
},
},
)
aioclient_mock.get(
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
)
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/addons/test/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test/info",
json={
"result": "ok",
"data": {
"name": "test",
"slug": "test",
"update_available": False,
"version": "1.0.0",
"version_latest": "1.0.0",
"repository": "core",
"state": "started",
"icon": False,
"url": "https://github.com/home-assistant/addons/test",
"auto_update": True,
},
},
)
aioclient_mock.get("http://127.0.0.1/addons/test2/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test2/info",
json={
"result": "ok",
"data": {
"name": "test2",
"slug": "test2",
"update_available": False,
"version": "1.0.0",
"version_latest": "1.0.0",
"repository": "core",
"state": "started",
"icon": False,
"url": "https://github.com",
"auto_update": False,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test2/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.8,
"memory_usage": 51941376,
"memory_limit": 3977146368,
"memory_percent": 1.31,
"network_rx": 31338284,
"network_tx": 15692900,
"blk_read": 740077568,
"blk_write": 6004736,
},
},
) |
Return an AddonManager instance. | def addon_manager_fixture(hass: HomeAssistant) -> AddonManager:
"""Return an AddonManager instance."""
return AddonManager(hass, LOGGER, "Test", "test_addon") |
Mock add-on not installed. | def addon_not_installed_fixture(
addon_store_info: AsyncMock, addon_info: AsyncMock
) -> AsyncMock:
"""Mock add-on not installed."""
addon_store_info.return_value["available"] = True
return addon_info |
Mock add-on already installed but not running. | def mock_addon_installed(
addon_store_info: AsyncMock, addon_info: AsyncMock
) -> AsyncMock:
"""Mock add-on already installed but not running."""
addon_store_info.return_value = {
"available": True,
"installed": "1.0.0",
"state": "stopped",
"version": "1.0.0",
}
addon_info.return_value["available"] = True
addon_info.return_value["hostname"] = "core-test-addon"
addon_info.return_value["state"] = "stopped"
addon_info.return_value["version"] = "1.0.0"
return addon_info |
Mock get add-on discovery info. | def get_addon_discovery_info_fixture() -> Generator[AsyncMock, None, None]:
"""Mock get add-on discovery info."""
with patch(
"homeassistant.components.hassio.addon_manager.async_get_addon_discovery_info"
) as get_addon_discovery_info:
yield get_addon_discovery_info |
Mock Supervisor add-on store info. | def addon_store_info_fixture() -> Generator[AsyncMock, None, None]:
"""Mock Supervisor add-on store info."""
with patch(
"homeassistant.components.hassio.addon_manager.async_get_addon_store_info"
) as addon_store_info:
addon_store_info.return_value = {
"available": False,
"installed": None,
"state": None,
"version": "1.0.0",
}
yield addon_store_info |
Mock Supervisor add-on info. | def addon_info_fixture() -> Generator[AsyncMock, None, None]:
"""Mock Supervisor add-on info."""
with patch(
"homeassistant.components.hassio.addon_manager.async_get_addon_info",
) as addon_info:
addon_info.return_value = {
"available": False,
"hostname": None,
"options": {},
"state": None,
"update_available": False,
"version": None,
}
yield addon_info |
Mock set add-on options. | def set_addon_options_fixture() -> Generator[AsyncMock, None, None]:
"""Mock set add-on options."""
with patch(
"homeassistant.components.hassio.addon_manager.async_set_addon_options"
) as set_options:
yield set_options |
Mock install add-on. | def install_addon_fixture() -> Generator[AsyncMock, None, None]:
"""Mock install add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_install_addon"
) as install_addon:
yield install_addon |
Mock uninstall add-on. | def uninstall_addon_fixture() -> Generator[AsyncMock, None, None]:
"""Mock uninstall add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_uninstall_addon"
) as uninstall_addon:
yield uninstall_addon |
Mock start add-on. | def start_addon_fixture() -> Generator[AsyncMock, None, None]:
"""Mock start add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_start_addon"
) as start_addon:
yield start_addon |
Mock restart add-on. | def restart_addon_fixture() -> Generator[AsyncMock, None, None]:
"""Mock restart add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_restart_addon"
) as restart_addon:
yield restart_addon |
Mock stop add-on. | def stop_addon_fixture() -> Generator[AsyncMock, None, None]:
"""Mock stop add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_stop_addon"
) as stop_addon:
yield stop_addon |
Mock create backup. | def create_backup_fixture() -> Generator[AsyncMock, None, None]:
"""Mock create backup."""
with patch(
"homeassistant.components.hassio.addon_manager.async_create_backup"
) as create_backup:
yield create_backup |
Mock update add-on. | def mock_update_addon() -> Generator[AsyncMock, None, None]:
"""Mock update add-on."""
with patch(
"homeassistant.components.hassio.addon_manager.async_update_addon"
) as update_addon:
yield update_addon |
Mock all setup requests. | def mock_all(aioclient_mock):
"""Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/homeassistant/info",
json={"result": "ok", "data": {"last_version": "10.0"}},
) |
Mock all setup requests. | def mock_all(aioclient_mock, request):
"""Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/info",
json={
"result": "ok",
"data": {
"supervisor": "222",
"homeassistant": "0.110.0",
"hassos": "1.2.3",
},
},
)
aioclient_mock.get(
"http://127.0.0.1/store",
json={
"result": "ok",
"data": {"addons": [], "repositories": []},
},
)
aioclient_mock.get(
"http://127.0.0.1/host/info",
json={
"result": "ok",
"data": {
"result": "ok",
"data": {
"chassis": "vm",
"operating_system": "Debian GNU/Linux 10 (buster)",
"kernel": "4.19.0-6-amd64",
},
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/info",
json={"result": "ok", "data": {"version_latest": "1.0.0", "version": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={
"result": "ok",
"data": {
"version_latest": "1.0.0",
"version": "1.0.0",
"update_available": False,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={
"result": "ok",
"data": {
"result": "ok",
"version": "1.0.0",
"version_latest": "1.0.0",
"auto_update": True,
"addons": [
{
"name": "test",
"state": "started",
"slug": "test",
"installed": True,
"update_available": True,
"version": "2.0.0",
"version_latest": "2.0.1",
"repository": "core",
"url": "https://github.com/home-assistant/addons/test",
},
{
"name": "test2",
"state": "stopped",
"slug": "test2",
"installed": True,
"update_available": False,
"version": "3.1.0",
"version_latest": "3.1.0",
"repository": "core",
"url": "https://github.com",
},
],
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get("http://127.0.0.1/addons/test/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test/info",
json={"result": "ok", "data": {"auto_update": True}},
)
aioclient_mock.get("http://127.0.0.1/addons/test2/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test2/info",
json={"result": "ok", "data": {"auto_update": False}},
)
aioclient_mock.get(
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
)
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/resolution/info",
json={
"result": "ok",
"data": {
"unsupported": [],
"unhealthy": [],
"suggestions": [],
"issues": [],
"checks": [],
},
},
) |
Mock all setup requests. | def mock_all(aioclient_mock, request):
"""Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/info",
json={
"result": "ok",
"data": {
"supervisor": "222",
"homeassistant": "0.110.0",
"hassos": "1.2.3",
},
},
)
aioclient_mock.get(
"http://127.0.0.1/store",
json={
"result": "ok",
"data": {"addons": [], "repositories": []},
},
)
aioclient_mock.get(
"http://127.0.0.1/host/info",
json={
"result": "ok",
"data": {
"result": "ok",
"data": {
"chassis": "vm",
"operating_system": "Debian GNU/Linux 10 (buster)",
"kernel": "4.19.0-6-amd64",
},
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/info",
json={
"result": "ok",
"data": {"version_latest": "1.0.0dev222", "version": "1.0.0dev221"},
},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={
"result": "ok",
"data": {
"version_latest": "1.0.0dev2222",
"version": "1.0.0dev2221",
"update_available": False,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={
"result": "ok",
"data": {
"result": "ok",
"version": "1.0.0",
"version_latest": "1.0.1dev222",
"addons": [
{
"name": "test",
"state": "started",
"slug": "test",
"installed": True,
"update_available": True,
"icon": False,
"version": "2.0.0",
"version_latest": "2.0.1",
"repository": "core",
"url": "https://github.com/home-assistant/addons/test",
},
{
"name": "test2",
"state": "stopped",
"slug": "test2",
"installed": True,
"update_available": False,
"icon": True,
"version": "3.1.0",
"version_latest": "3.1.0",
"repository": "core",
"url": "https://github.com",
},
],
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get("http://127.0.0.1/addons/test/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test/info",
json={"result": "ok", "data": {"auto_update": True}},
)
aioclient_mock.get("http://127.0.0.1/addons/test2/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test2/info",
json={"result": "ok", "data": {"auto_update": False}},
)
aioclient_mock.get(
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
)
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/resolution/info",
json={
"result": "ok",
"data": {
"unsupported": [],
"unhealthy": [],
"suggestions": [],
"issues": [],
"checks": [],
},
},
) |
Mock that we're not onboarded. | def mock_not_onboarded():
"""Mock that we're not onboarded."""
with patch(
"homeassistant.components.hassio.http.async_is_onboarded", return_value=False
):
yield |
Return a Hass.io HTTP client tied to a non-admin user. | def hassio_user_client(hassio_client, hass_admin_user):
"""Return a Hass.io HTTP client tied to a non-admin user."""
hass_admin_user.groups = []
return hassio_client |
Extra os/info. | def extra_os_info():
"""Extra os/info."""
return {} |
Mock os/info. | def os_info(extra_os_info):
"""Mock os/info."""
return {
"json": {
"result": "ok",
"data": {"version_latest": "1.0.0", "version": "1.0.0", **extra_os_info},
}
} |
Mock all setup requests. | def mock_all(aioclient_mock, request, os_info):
"""Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/info",
json={
"result": "ok",
"data": {
"supervisor": "222",
"homeassistant": "0.110.0",
"hassos": "1.2.3",
},
},
)
aioclient_mock.get(
"http://127.0.0.1/store",
json={
"result": "ok",
"data": {"addons": [], "repositories": []},
},
)
aioclient_mock.get(
"http://127.0.0.1/host/info",
json={
"result": "ok",
"data": {
"result": "ok",
"data": {
"chassis": "vm",
"operating_system": "Debian GNU/Linux 10 (buster)",
"kernel": "4.19.0-6-amd64",
},
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/info",
json={"result": "ok", "data": {"version_latest": "1.0.0", "version": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
**os_info,
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={
"result": "ok",
"data": {
"version_latest": "1.0.0",
"version": "1.0.0",
"auto_update": True,
"addons": [
{
"name": "test",
"slug": "test",
"state": "stopped",
"update_available": False,
"version": "1.0.0",
"version_latest": "1.0.0",
"repository": "core",
"icon": False,
},
{
"name": "test2",
"slug": "test2",
"state": "stopped",
"update_available": False,
"version": "1.0.0",
"version_latest": "1.0.0",
"repository": "core",
"icon": False,
},
],
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test2/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.8,
"memory_usage": 51941376,
"memory_limit": 3977146368,
"memory_percent": 1.31,
"network_rx": 31338284,
"network_tx": 15692900,
"blk_read": 740077568,
"blk_write": 6004736,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test3/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.8,
"memory_usage": 51941376,
"memory_limit": 3977146368,
"memory_percent": 1.31,
"network_rx": 31338284,
"network_tx": 15692900,
"blk_read": 740077568,
"blk_write": 6004736,
},
},
)
aioclient_mock.get("http://127.0.0.1/addons/test/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test/info",
json={"result": "ok", "data": {"auto_update": True}},
)
aioclient_mock.get("http://127.0.0.1/addons/test2/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test2/info",
json={"result": "ok", "data": {"auto_update": False}},
)
aioclient_mock.get(
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
)
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/resolution/info",
json={
"result": "ok",
"data": {
"unsupported": [],
"unhealthy": [],
"suggestions": [],
"issues": [],
"checks": [],
},
},
) |
Test hostname_from_addon_slug. | def test_hostname_from_addon_slug() -> None:
"""Test hostname_from_addon_slug."""
assert hostname_from_addon_slug("mqtt") == "mqtt"
assert (
hostname_from_addon_slug("core_silabs_multiprotocol")
== "core-silabs-multiprotocol"
) |
Mock resolution/info endpoint with unsupported/unhealthy reasons and/or issues. | def mock_resolution_info(
aioclient_mock: AiohttpClientMocker,
unsupported: list[str] | None = None,
unhealthy: list[str] | None = None,
issues: list[dict[str, str]] | None = None,
suggestion_result: str = "ok",
):
"""Mock resolution/info endpoint with unsupported/unhealthy reasons and/or issues."""
aioclient_mock.get(
"http://127.0.0.1/resolution/info",
json={
"result": "ok",
"data": {
"unsupported": unsupported or [],
"unhealthy": unhealthy or [],
"suggestions": [],
"issues": [
{k: v for k, v in issue.items() if k != "suggestions"}
for issue in issues
]
if issues
else [],
"checks": [
{"enabled": True, "slug": "supervisor_trust"},
{"enabled": True, "slug": "free_space"},
],
},
},
)
if issues:
suggestions_by_issue = {
issue["uuid"]: issue.get("suggestions", []) for issue in issues
}
for issue_uuid, suggestions in suggestions_by_issue.items():
aioclient_mock.get(
f"http://127.0.0.1/resolution/issue/{issue_uuid}/suggestions",
json={"result": "ok", "data": {"suggestions": suggestions}},
)
for suggestion in suggestions:
aioclient_mock.post(
f"http://127.0.0.1/resolution/suggestion/{suggestion['uuid']}",
json={"result": suggestion_result},
) |
Assert repair for unhealthy/unsupported in list. | def assert_repair_in_list(issues: list[dict[str, Any]], unhealthy: bool, reason: str):
"""Assert repair for unhealthy/unsupported in list."""
repair_type = "unhealthy" if unhealthy else "unsupported"
assert {
"breaks_in_ha_version": None,
"created": ANY,
"dismissed_version": None,
"domain": "hassio",
"ignored": False,
"is_fixable": False,
"issue_id": f"{repair_type}_system_{reason}",
"issue_domain": None,
"learn_more_url": f"https://www.home-assistant.io/more-info/{repair_type}/{reason}",
"severity": "critical" if unhealthy else "warning",
"translation_key": f"{repair_type}_{reason}",
"translation_placeholders": None,
} in issues |
Assert repair for unhealthy/unsupported in list. | def assert_issue_repair_in_list(
issues: list[dict[str, Any]],
uuid: str,
context: str,
type_: str,
fixable: bool,
reference: str | None,
):
"""Assert repair for unhealthy/unsupported in list."""
assert {
"breaks_in_ha_version": None,
"created": ANY,
"dismissed_version": None,
"domain": "hassio",
"ignored": False,
"is_fixable": fixable,
"issue_id": uuid,
"issue_domain": None,
"learn_more_url": None,
"severity": "warning",
"translation_key": f"issue_{context}_{type_}",
"translation_placeholders": {"reference": reference} if reference else None,
} in issues |
Mock all setup requests. | def mock_all(aioclient_mock: AiohttpClientMocker, request):
"""Mock all setup requests."""
_install_default_mocks(aioclient_mock)
_install_test_addon_stats_mock(aioclient_mock) |
Install mock to provide valid stats for the test addon. | def _install_test_addon_stats_mock(aioclient_mock: AiohttpClientMocker):
"""Install mock to provide valid stats for the test addon."""
aioclient_mock.get(
"http://127.0.0.1/addons/test/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
) |
Install mocks to raise an exception when fetching stats for the test addon. | def _install_test_addon_stats_failure_mock(aioclient_mock: AiohttpClientMocker):
"""Install mocks to raise an exception when fetching stats for the test addon."""
aioclient_mock.get(
"http://127.0.0.1/addons/test/stats",
exc=HassioAPIError,
) |
Install default mocks. | def _install_default_mocks(aioclient_mock: AiohttpClientMocker):
"""Install default mocks."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/info",
json={
"result": "ok",
"data": {
"supervisor": "222",
"homeassistant": "0.110.0",
"hassos": "1.2.3",
},
},
)
aioclient_mock.get(
"http://127.0.0.1/store",
json={
"result": "ok",
"data": {"addons": [], "repositories": []},
},
)
aioclient_mock.get(
"http://127.0.0.1/host/info",
json={
"result": "ok",
"data": {
"agent_version": "1.0.0",
"chassis": "vm",
"operating_system": "Debian GNU/Linux 10 (buster)",
"kernel": "4.19.0-6-amd64",
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/info",
json={"result": "ok", "data": {"version_latest": "1.0.0", "version": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={"result": "ok", "data": {"version_latest": "1.0.0", "version": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={
"result": "ok",
"data": {
"result": "ok",
"version": "1.0.0",
"version_latest": "1.0.0",
"auto_update": True,
"addons": [
{
"name": "test",
"state": "started",
"slug": "test",
"installed": True,
"update_available": False,
"version": "2.0.0",
"version_latest": "2.0.1",
"repository": "core",
"url": "https://github.com/home-assistant/addons/test",
"icon": False,
},
{
"name": "test2",
"state": "stopped",
"slug": "test2",
"installed": True,
"update_available": False,
"version": "3.1.0",
"version_latest": "3.2.0",
"repository": "core",
"url": "https://github.com",
"icon": False,
},
],
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get("http://127.0.0.1/addons/test/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test/info",
json={"result": "ok", "data": {"auto_update": True}},
)
aioclient_mock.get("http://127.0.0.1/addons/test2/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test2/info",
json={"result": "ok", "data": {"auto_update": False}},
)
aioclient_mock.get(
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
)
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/resolution/info",
json={
"result": "ok",
"data": {
"unsupported": [],
"unhealthy": [],
"suggestions": [],
"issues": [],
"checks": [],
},
},
) |
Mock all setup requests. | def mock_all(aioclient_mock, request):
"""Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/info",
json={
"result": "ok",
"data": {
"supervisor": "222",
"homeassistant": "0.110.0",
"hassos": "1.2.3",
},
},
)
aioclient_mock.get(
"http://127.0.0.1/store",
json={
"result": "ok",
"data": {"addons": [], "repositories": []},
},
)
aioclient_mock.get(
"http://127.0.0.1/host/info",
json={
"result": "ok",
"data": {
"result": "ok",
"data": {
"chassis": "vm",
"operating_system": "Debian GNU/Linux 10 (buster)",
"kernel": "4.19.0-6-amd64",
},
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/info",
json={
"result": "ok",
"data": {"version_latest": "1.0.0dev222", "version": "1.0.0dev221"},
},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={
"result": "ok",
"data": {
"version_latest": "1.0.0dev2222",
"version": "1.0.0dev2221",
"update_available": False,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={
"result": "ok",
"data": {
"result": "ok",
"version": "1.0.0",
"version_latest": "1.0.1dev222",
"auto_update": True,
"addons": [
{
"name": "test",
"state": "started",
"slug": "test",
"installed": True,
"update_available": True,
"icon": False,
"version": "2.0.0",
"version_latest": "2.0.1",
"repository": "core",
"url": "https://github.com/home-assistant/addons/test",
},
{
"name": "test2",
"state": "stopped",
"slug": "test2",
"installed": True,
"update_available": False,
"icon": True,
"version": "3.1.0",
"version_latest": "3.1.0",
"repository": "core",
"url": "https://github.com",
},
],
},
},
)
aioclient_mock.get(
"http://127.0.0.1/addons/test/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/stats",
json={
"result": "ok",
"data": {
"cpu_percent": 0.99,
"memory_usage": 182611968,
"memory_limit": 3977146368,
"memory_percent": 4.59,
"network_rx": 362570232,
"network_tx": 82374138,
"blk_read": 46010945536,
"blk_write": 15051526144,
},
},
)
aioclient_mock.get("http://127.0.0.1/addons/test/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test/info",
json={"result": "ok", "data": {"auto_update": True}},
)
aioclient_mock.get("http://127.0.0.1/addons/test2/changelog", text="")
aioclient_mock.get(
"http://127.0.0.1/addons/test2/info",
json={"result": "ok", "data": {"auto_update": False}},
)
aioclient_mock.get(
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
)
aioclient_mock.post("http://127.0.0.1/refresh_updates", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/resolution/info",
json={
"result": "ok",
"data": {
"unsupported": [],
"unhealthy": [],
"suggestions": [],
"issues": [],
"checks": [],
},
},
) |
Mock all setup requests. | def mock_all(aioclient_mock):
"""Mock all setup requests."""
aioclient_mock.post("http://127.0.0.1/homeassistant/options", json={"result": "ok"})
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
aioclient_mock.post("http://127.0.0.1/supervisor/options", json={"result": "ok"})
aioclient_mock.get(
"http://127.0.0.1/info",
json={
"result": "ok",
"data": {"supervisor": "222", "homeassistant": "0.110.0", "hassos": None},
},
)
aioclient_mock.get(
"http://127.0.0.1/host/info",
json={
"result": "ok",
"data": {
"result": "ok",
"data": {
"chassis": "vm",
"operating_system": "Debian GNU/Linux 10 (buster)",
"kernel": "4.19.0-6-amd64",
},
},
},
)
aioclient_mock.get(
"http://127.0.0.1/core/info",
json={"result": "ok", "data": {"version_latest": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/os/info",
json={"result": "ok", "data": {"version_latest": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/supervisor/info",
json={"result": "ok", "data": {"version_latest": "1.0.0"}},
)
aioclient_mock.get(
"http://127.0.0.1/ingress/panels", json={"result": "ok", "data": {"panels": {}}}
)
aioclient_mock.get(
"http://127.0.0.1/resolution/info",
json={
"result": "ok",
"data": {
"unsupported": [],
"unhealthy": [],
"suggestions": [],
"issues": [],
"checks": [],
},
},
) |
Mock telnet. | def telnetmock():
"""Mock telnet."""
with patch("telnetlib.Telnet", new=TelnetMock):
yield |
Mock CecAdapter.
Always mocked as it imports the `cec` library which is part of `libcec`. | def mock_cec_adapter_fixture():
"""Mock CecAdapter.
Always mocked as it imports the `cec` library which is part of `libcec`.
"""
with patch(
"homeassistant.components.hdmi_cec.CecAdapter", autospec=True
) as mock_cec_adapter:
yield mock_cec_adapter |
Mock HDMINetwork. | def mock_hdmi_network_fixture():
"""Mock HDMINetwork."""
with patch(
"homeassistant.components.hdmi_cec.HDMINetwork", autospec=True
) as mock_hdmi_network:
yield mock_hdmi_network |
Create an initialized mock hdmi_network. | def create_hdmi_network(hass, mock_hdmi_network):
"""Create an initialized mock hdmi_network."""
async def hdmi_network(config=None):
if not config:
config = {}
await async_setup_component(hass, DOMAIN, {DOMAIN: config})
mock_hdmi_network_instance = mock_hdmi_network.return_value
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
return mock_hdmi_network_instance
return hdmi_network |
Create a CecEntity. | def create_cec_entity(hass):
"""Create a CecEntity."""
async def cec_entity(hdmi_network, device):
new_device_callback = hdmi_network.set_new_device_callback.call_args.args[0]
new_device_callback(device)
await hass.async_block_till_done()
return cec_entity |
Mock TcpAdapter. | def mock_tcp_adapter_fixture():
"""Mock TcpAdapter."""
with patch(
"homeassistant.components.hdmi_cec.TcpAdapter", autospec=True
) as mock_tcp_adapter:
yield mock_tcp_adapter |
Test the device config mapping function. | def test_parse_mapping_physical_address(mapping, expected) -> None:
"""Test the device config mapping function."""
result = parse_mapping(mapping)
result = [
(r[0], str(r[1]) if isinstance(r[1], PhysicalAddress) else r[1]) for r in result
]
assert result == expected |
Allow for skipping the assert state changes.
This is broken in this entity, but we still want to test that
the rest of the code works as expected. | def assert_state_fixture(hass, request):
"""Allow for skipping the assert state changes.
This is broken in this entity, but we still want to test that
the rest of the code works as expected.
"""
def test_state(state, expected):
if request.param:
assert state == expected
else:
assert True
return test_state |
Assert that correct KeyPressCommand & KeyReleaseCommand where sent. | def assert_key_press_release(fnc, count=0, *, dst, key):
"""Assert that correct KeyPressCommand & KeyReleaseCommand where sent."""
assert fnc.call_count >= count * 2 + 1
press_arg = fnc.call_args_list[count * 2].args[0]
release_arg = fnc.call_args_list[count * 2 + 1].args[0]
assert isinstance(press_arg, KeyPressCommand)
assert press_arg.key == key
assert press_arg.dst == dst
assert isinstance(release_arg, KeyReleaseCommand)
assert release_arg.dst == dst |
Create a mock HEOS config entry. | def config_entry_fixture():
"""Create a mock HEOS config entry."""
return MockConfigEntry(
domain=DOMAIN, data={CONF_HOST: "127.0.0.1"}, title="Controller (127.0.0.1)"
) |
Create a mock Heos controller fixture. | def controller_fixture(
players, favorites, input_sources, playlists, change_data, dispatcher, group
):
"""Create a mock Heos controller fixture."""
mock_heos = Mock(Heos)
for player in players.values():
player.heos = mock_heos
mock_heos.dispatcher = dispatcher
mock_heos.get_players.return_value = players
mock_heos.players = players
mock_heos.get_favorites.return_value = favorites
mock_heos.get_input_sources.return_value = input_sources
mock_heos.get_playlists.return_value = playlists
mock_heos.load_players.return_value = change_data
mock_heos.is_signed_in = True
mock_heos.signed_in_username = "[email protected]"
mock_heos.connection_state = const.STATE_CONNECTED
mock_heos.get_groups.return_value = group
mock_heos.create_group.return_value = None
mock = Mock(return_value=mock_heos)
with (
patch("homeassistant.components.heos.Heos", new=mock),
patch("homeassistant.components.heos.config_flow.Heos", new=mock),
):
yield mock_heos |
Create hass config fixture. | def config_fixture():
"""Create hass config fixture."""
return {DOMAIN: {CONF_HOST: "127.0.0.1"}} |
Create two mock HeosPlayers. | def player_fixture(quick_selects):
"""Create two mock HeosPlayers."""
players = {}
for i in (1, 2):
player = Mock(HeosPlayer)
player.player_id = i
if i > 1:
player.name = f"Test Player {i}"
else:
player.name = "Test Player"
player.model = "Test Model"
player.version = "1.0.0"
player.is_muted = False
player.available = True
player.state = const.PLAY_STATE_STOP
player.ip_address = f"127.0.0.{i}"
player.network = "wired"
player.shuffle = False
player.repeat = const.REPEAT_OFF
player.volume = 25
player.now_playing_media.supported_controls = const.CONTROLS_ALL
player.now_playing_media.album_id = 1
player.now_playing_media.queue_id = 1
player.now_playing_media.source_id = 1
player.now_playing_media.station = "Station Name"
player.now_playing_media.type = "Station"
player.now_playing_media.album = "Album"
player.now_playing_media.artist = "Artist"
player.now_playing_media.media_id = "1"
player.now_playing_media.duration = None
player.now_playing_media.current_position = None
player.now_playing_media.image_url = "http://"
player.now_playing_media.song = "Song"
player.get_quick_selects.return_value = quick_selects
players[player.player_id] = player
return players |
Create a HEOS group consisting of two players. | def group_fixture(players):
"""Create a HEOS group consisting of two players."""
group = Mock(HeosGroup)
group.leader = players[1]
group.members = [players[2]]
group.group_id = 999
return {group.group_id: group} |
Create favorites fixture. | def favorites_fixture() -> dict[int, HeosSource]:
"""Create favorites fixture."""
station = Mock(HeosSource)
station.type = const.TYPE_STATION
station.name = "Today's Hits Radio"
station.media_id = "123456789"
radio = Mock(HeosSource)
radio.type = const.TYPE_STATION
radio.name = "Classical MPR (Classical Music)"
radio.media_id = "s1234"
return {1: station, 2: radio} |
Create a set of input sources for testing. | def input_sources_fixture() -> Sequence[InputSource]:
"""Create a set of input sources for testing."""
source = Mock(InputSource)
source.player_id = 1
source.input_name = const.INPUT_AUX_IN_1
source.name = "HEOS Drive - Line In 1"
return [source] |
Create a dispatcher for testing. | def dispatcher_fixture() -> Dispatcher:
"""Create a dispatcher for testing."""
return Dispatcher() |
Return mock discovery data for testing. | def discovery_data_fixture() -> dict:
"""Return mock discovery data for testing."""
return ssdp.SsdpServiceInfo(
ssdp_usn="mock_usn",
ssdp_st="mock_st",
ssdp_location="http://127.0.0.1:60006/upnp/desc/aios_device/aios_device.xml",
upnp={
ssdp.ATTR_UPNP_DEVICE_TYPE: "urn:schemas-denon-com:device:AiosDevice:1",
ssdp.ATTR_UPNP_FRIENDLY_NAME: "Office",
ssdp.ATTR_UPNP_MANUFACTURER: "Denon",
ssdp.ATTR_UPNP_MODEL_NAME: "HEOS Drive",
ssdp.ATTR_UPNP_MODEL_NUMBER: "DWSA-10 4.0",
ssdp.ATTR_UPNP_SERIAL: None,
ssdp.ATTR_UPNP_UDN: "uuid:e61de70c-2250-1c22-0080-0005cdf512be",
},
) |
Create a dict of quick selects for testing. | def quick_selects_fixture() -> dict[int, str]:
"""Create a dict of quick selects for testing."""
return {
1: "Quick Select 1",
2: "Quick Select 2",
3: "Quick Select 3",
4: "Quick Select 4",
5: "Quick Select 5",
6: "Quick Select 6",
} |
Create favorites fixture. | def playlists_fixture() -> Sequence[HeosSource]:
"""Create favorites fixture."""
playlist = Mock(HeosSource)
playlist.type = const.TYPE_PLAYLIST
playlist.name = "Awesome Music"
return [playlist] |
Create player change data for testing. | def change_data_fixture() -> dict:
"""Create player change data for testing."""
return {const.DATA_MAPPED_IDS: {}, const.DATA_NEW: []} |
Create player change data for testing. | def change_data_mapped_ids_fixture() -> dict:
"""Create player change data for testing."""
return {const.DATA_MAPPED_IDS: {101: 1}, const.DATA_NEW: []} |
Return valid api response. | def valid_response_fixture():
"""Return valid api response."""
with (
patch("here_transit.HERETransitApi.route", return_value=TRANSIT_RESPONSE),
patch(
"here_routing.HERERoutingApi.route",
return_value=RESPONSE,
) as mock,
):
yield mock |
Return valid api response. | def bike_response_fixture():
"""Return valid api response."""
with (
patch("here_transit.HERETransitApi.route", return_value=TRANSIT_RESPONSE),
patch(
"here_routing.HERERoutingApi.route",
return_value=BIKE_RESPONSE,
) as mock,
):
yield mock |
Return valid api response without attribution. | def no_attribution_response_fixture():
"""Return valid api response without attribution."""
with (
patch(
"here_transit.HERETransitApi.route",
return_value=NO_ATTRIBUTION_TRANSIT_RESPONSE,
),
patch(
"here_routing.HERERoutingApi.route",
return_value=RESPONSE,
) as mock,
):
yield mock |
Prevent setup. | def bypass_setup_fixture():
"""Prevent setup."""
with patch(
"homeassistant.components.here_travel_time.async_setup_entry",
return_value=True,
):
yield |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.