Final clean up of helpers accessed via hass (#72032)
* Final clean up of helpers accessed via hass * Fix circular dep * Fix import
This commit is contained in:
parent
d1d6c6b923
commit
bfb47eb212
17 changed files with 75 additions and 82 deletions
|
@ -22,6 +22,7 @@ from homeassistant.core import HomeAssistant, ServiceCall, callback
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import config_validation as cv, entityfilter
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
|
@ -267,15 +268,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
return
|
||||
loaded = True
|
||||
|
||||
await hass.helpers.discovery.async_load_platform(
|
||||
Platform.BINARY_SENSOR, DOMAIN, {}, config
|
||||
)
|
||||
await hass.helpers.discovery.async_load_platform(
|
||||
Platform.STT, DOMAIN, {}, config
|
||||
)
|
||||
await hass.helpers.discovery.async_load_platform(
|
||||
Platform.TTS, DOMAIN, {}, config
|
||||
)
|
||||
await async_load_platform(hass, Platform.BINARY_SENSOR, DOMAIN, {}, config)
|
||||
await async_load_platform(hass, Platform.STT, DOMAIN, {}, config)
|
||||
await async_load_platform(hass, Platform.TTS, DOMAIN, {}, config)
|
||||
|
||||
async_dispatcher_send(
|
||||
hass, SIGNAL_CLOUD_CONNECTION_STATE, CloudConnectionState.CLOUD_CONNECTED
|
||||
|
|
|
@ -18,6 +18,7 @@ from homeassistant.const import (
|
|||
)
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
|
@ -71,9 +72,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
# Set up demo platforms
|
||||
for platform in COMPONENTS_WITH_DEMO_PLATFORM:
|
||||
hass.async_create_task(
|
||||
hass.helpers.discovery.async_load_platform(platform, DOMAIN, {}, config)
|
||||
)
|
||||
hass.async_create_task(async_load_platform(hass, platform, DOMAIN, {}, config))
|
||||
|
||||
config.setdefault(ha.DOMAIN, {})
|
||||
config.setdefault(DOMAIN, {})
|
||||
|
|
|
@ -46,7 +46,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import CoreState, HomeAssistant, ServiceCall, State, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, Unauthorized
|
||||
from homeassistant.helpers import device_registry, entity_registry
|
||||
from homeassistant.helpers import device_registry, entity_registry, instance_id
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entityfilter import (
|
||||
BASE_FILTER_SCHEMA,
|
||||
|
@ -726,7 +726,7 @@ class HomeKit:
|
|||
return
|
||||
self.status = STATUS_WAIT
|
||||
async_zc_instance = await zeroconf.async_get_async_instance(self.hass)
|
||||
uuid = await self.hass.helpers.instance_id.async_get()
|
||||
uuid = await instance_id.async_get(self.hass)
|
||||
await self.hass.async_add_executor_job(self.setup, async_zc_instance, uuid)
|
||||
self.aid_storage = AccessoryAidStorage(self.hass, self._entry_id)
|
||||
await self.aid_storage.async_initialize()
|
||||
|
|
|
@ -16,6 +16,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.discovery import load_platform
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
|
@ -152,6 +153,6 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
submit_tv_request,
|
||||
schema=SUBMIT_TV_REQUEST_SERVICE_SCHEMA,
|
||||
)
|
||||
hass.helpers.discovery.load_platform(Platform.SENSOR, DOMAIN, {}, config)
|
||||
load_platform(hass, Platform.SENSOR, DOMAIN, {}, config)
|
||||
|
||||
return True
|
||||
|
|
|
@ -14,6 +14,7 @@ from homeassistant.components.http.const import KEY_HASS_REFRESH_TOKEN_ID
|
|||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
from homeassistant.components.http.view import HomeAssistantView
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import area_registry as ar
|
||||
from homeassistant.helpers.system_info import async_get_system_info
|
||||
from homeassistant.helpers.translation import async_get_translations
|
||||
|
||||
|
@ -152,7 +153,7 @@ class UserOnboardingView(_BaseOnboardingView):
|
|||
hass, data["language"], "area", {DOMAIN}
|
||||
)
|
||||
|
||||
area_registry = await hass.helpers.area_registry.async_get_registry()
|
||||
area_registry = ar.async_get(hass)
|
||||
|
||||
for area in DEFAULT_AREAS:
|
||||
area_registry.async_create(
|
||||
|
|
|
@ -21,6 +21,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers.update_coordinator import (
|
||||
CoordinatorEntity,
|
||||
|
@ -178,9 +179,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
for component in PLATFORMS:
|
||||
await hass.async_create_task(
|
||||
hass.helpers.discovery.async_load_platform(
|
||||
component, DOMAIN, {"config": config}, config
|
||||
)
|
||||
async_load_platform(hass, component, DOMAIN, {"config": config}, config)
|
||||
)
|
||||
|
||||
return True
|
||||
|
|
|
@ -16,8 +16,9 @@ from homeassistant.const import (
|
|||
__version__ as current_version,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform, instance_id
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
from homeassistant.helpers.system_info import async_get_system_info
|
||||
from homeassistant.loader import Integration, async_get_custom_components
|
||||
|
||||
from .const import (
|
||||
|
@ -67,8 +68,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
# Additional/extra data collection
|
||||
channel = get_channel(current_version)
|
||||
huuid = await hass.helpers.instance_id.async_get()
|
||||
system_info = await hass.helpers.system_info.async_get_system_info()
|
||||
huuid = await instance_id.async_get(hass)
|
||||
system_info = await async_get_system_info(hass)
|
||||
custom_components = await async_get_custom_components(hass)
|
||||
|
||||
tracing = {}
|
||||
|
@ -100,7 +101,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
async def update_system_info(now):
|
||||
nonlocal system_info
|
||||
system_info = await hass.helpers.system_info.async_get_system_info()
|
||||
system_info = await async_get_system_info(hass)
|
||||
|
||||
# Update system info every hour
|
||||
async_call_later(hass, 3600, update_system_info)
|
||||
|
|
|
@ -28,7 +28,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import BaseServiceInfo
|
||||
from homeassistant.helpers import discovery_flow
|
||||
from homeassistant.helpers import discovery_flow, instance_id
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
@ -198,7 +198,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
Wait till started or otherwise HTTP is not up and running.
|
||||
"""
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
uuid = await instance_id.async_get(hass)
|
||||
await _async_register_hass_zc_service(hass, aio_zc, uuid)
|
||||
|
||||
async def _async_zeroconf_hass_stop(_event: Event) -> None:
|
||||
|
|
|
@ -420,6 +420,10 @@ class DeviceRegistry:
|
|||
via_device_id: str | None | UndefinedType = UNDEFINED,
|
||||
) -> DeviceEntry | None:
|
||||
"""Update device attributes."""
|
||||
# Circular dep
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from . import area_registry as ar
|
||||
|
||||
old = self.devices[device_id]
|
||||
|
||||
new_values: dict[str, Any] = {} # Dict with new key/value pairs
|
||||
|
@ -442,13 +446,13 @@ class DeviceRegistry:
|
|||
disabled_by = DeviceEntryDisabler(disabled_by)
|
||||
|
||||
if (
|
||||
suggested_area not in (UNDEFINED, None, "")
|
||||
suggested_area is not None
|
||||
and suggested_area is not UNDEFINED
|
||||
and suggested_area != ""
|
||||
and area_id is UNDEFINED
|
||||
and old.area_id is None
|
||||
):
|
||||
area = self.hass.helpers.area_registry.async_get(
|
||||
self.hass
|
||||
).async_get_or_create(suggested_area)
|
||||
area = ar.async_get(self.hass).async_get_or_create(suggested_area)
|
||||
area_id = area.id
|
||||
|
||||
if (
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from unittest.mock import Mock, patch
|
||||
|
||||
from homeassistant.components.cloud.const import DISPATCHER_REMOTE_UPDATE
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -14,9 +15,7 @@ async def test_remote_connection_sensor(hass):
|
|||
assert hass.states.get("binary_sensor.remote_ui") is None
|
||||
|
||||
# Fake connection/discovery
|
||||
await hass.helpers.discovery.async_load_platform(
|
||||
"binary_sensor", "cloud", {}, {"cloud": {}}
|
||||
)
|
||||
await async_load_platform(hass, "binary_sensor", "cloud", {}, {"cloud": {}})
|
||||
|
||||
# Mock test env
|
||||
cloud = hass.data["cloud"] = Mock()
|
||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.components.config import config_entries
|
|||
from homeassistant.config_entries import HANDLERS, ConfigFlow
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.generated import config_flows
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers import config_entry_flow, config_validation as cv
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import (
|
||||
|
@ -68,9 +68,7 @@ async def test_get_entries(hass, client, clear_handlers):
|
|||
"""Return options flow support for this handler."""
|
||||
return True
|
||||
|
||||
hass.helpers.config_entry_flow.register_discovery_flow(
|
||||
"comp2", "Comp 2", lambda: None
|
||||
)
|
||||
config_entry_flow.register_discovery_flow("comp2", "Comp 2", lambda: None)
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain="comp1",
|
||||
|
|
|
@ -183,8 +183,8 @@ async def test_modern_turn_on_invalid(hass, start_state):
|
|||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
# Turn on with an invalid config (speed, percentage, preset_modes all None)
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_INVALID_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass, [State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_INVALID_STATE)]
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
|
@ -227,8 +227,8 @@ async def test_modern_turn_on_percentage_from_different_speed(hass, start_state)
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PERCENTAGE15_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass, [State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PERCENTAGE15_STATE)]
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
|
@ -256,8 +256,8 @@ async def test_modern_turn_on_percentage_from_same_speed(hass):
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PERCENTAGE15_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass, [State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PERCENTAGE15_STATE)]
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
|
@ -293,8 +293,8 @@ async def test_modern_turn_on_preset_mode_from_different_speed(hass, start_state
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PRESET_MODE_AUTO_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass, [State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PRESET_MODE_AUTO_STATE)]
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
|
@ -324,8 +324,8 @@ async def test_modern_turn_on_preset_mode_from_same_speed(hass):
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PRESET_MODE_AUTO_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass, [State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PRESET_MODE_AUTO_STATE)]
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
|
@ -361,8 +361,9 @@ async def test_modern_turn_on_preset_mode_reverse(hass, start_state):
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_PRESET_MODE_AUTO_REVERSE_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass,
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_PRESET_MODE_AUTO_REVERSE_STATE)],
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
|
@ -403,8 +404,8 @@ async def test_modern_to_preset(hass, start_state):
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PRESET_MODE_AUTO_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass, [State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PRESET_MODE_AUTO_STATE)]
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 0
|
||||
|
@ -439,8 +440,8 @@ async def test_modern_to_percentage(hass, start_state):
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PERCENTAGE15_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass, [State(MODERN_FAN_ENTITY, "on", MODERN_FAN_ON_PERCENTAGE15_STATE)]
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 0
|
||||
|
@ -467,8 +468,9 @@ async def test_modern_direction(hass):
|
|||
set_percentage_mode = async_mock_service(hass, "fan", "set_percentage")
|
||||
set_preset_mode = async_mock_service(hass, "fan", "set_preset_mode")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_PRESET_MODE_AUTO_REVERSE_STATE)]
|
||||
await async_reproduce_state(
|
||||
hass,
|
||||
[State(MODERN_FAN_ENTITY, "on", MODERN_FAN_PRESET_MODE_AUTO_REVERSE_STATE)],
|
||||
)
|
||||
|
||||
assert len(turn_on_calls) == 0
|
||||
|
|
|
@ -49,7 +49,7 @@ from homeassistant.const import (
|
|||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistantError, State
|
||||
from homeassistant.helpers import device_registry, entity_registry as er
|
||||
from homeassistant.helpers import device_registry, entity_registry as er, instance_id
|
||||
from homeassistant.helpers.entityfilter import (
|
||||
CONF_EXCLUDE_DOMAINS,
|
||||
CONF_EXCLUDE_ENTITIES,
|
||||
|
@ -201,7 +201,7 @@ async def test_homekit_setup(hass, hk_driver, mock_async_zeroconf):
|
|||
hass.states.async_set("light.demo", "on")
|
||||
hass.states.async_set("light.demo2", "on")
|
||||
zeroconf_mock = MagicMock()
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
uuid = await instance_id.async_get(hass)
|
||||
with patch(f"{PATH_HOMEKIT}.HomeDriver", return_value=hk_driver) as mock_driver:
|
||||
await hass.async_add_executor_job(homekit.setup, zeroconf_mock, uuid)
|
||||
|
||||
|
@ -245,7 +245,7 @@ async def test_homekit_setup_ip_address(hass, hk_driver, mock_async_zeroconf):
|
|||
)
|
||||
|
||||
path = get_persist_fullpath_for_entry_id(hass, entry.entry_id)
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
uuid = await instance_id.async_get(hass)
|
||||
with patch(f"{PATH_HOMEKIT}.HomeDriver", return_value=hk_driver) as mock_driver:
|
||||
await hass.async_add_executor_job(homekit.setup, mock_async_zeroconf, uuid)
|
||||
mock_driver.assert_called_with(
|
||||
|
@ -287,7 +287,7 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver, mock_async_zeroconf):
|
|||
|
||||
async_zeroconf_instance = MagicMock()
|
||||
path = get_persist_fullpath_for_entry_id(hass, entry.entry_id)
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
uuid = await instance_id.async_get(hass)
|
||||
with patch(f"{PATH_HOMEKIT}.HomeDriver", return_value=hk_driver) as mock_driver:
|
||||
await hass.async_add_executor_job(homekit.setup, async_zeroconf_instance, uuid)
|
||||
mock_driver.assert_called_with(
|
||||
|
|
|
@ -88,16 +88,12 @@ async def test_migrate_transient_devices(
|
|||
)
|
||||
|
||||
assert (
|
||||
len(
|
||||
hass.helpers.entity_registry.async_entries_for_device(
|
||||
entity_registry, device_id=plexweb_device.id
|
||||
)
|
||||
)
|
||||
len(er.async_entries_for_device(entity_registry, device_id=plexweb_device.id))
|
||||
== 1
|
||||
)
|
||||
assert (
|
||||
len(
|
||||
hass.helpers.entity_registry.async_entries_for_device(
|
||||
er.async_entries_for_device(
|
||||
entity_registry, device_id=non_plexweb_device.id
|
||||
)
|
||||
)
|
||||
|
@ -113,16 +109,12 @@ async def test_migrate_transient_devices(
|
|||
)
|
||||
|
||||
assert (
|
||||
len(
|
||||
hass.helpers.entity_registry.async_entries_for_device(
|
||||
entity_registry, device_id=plexweb_device.id
|
||||
)
|
||||
)
|
||||
len(er.async_entries_for_device(entity_registry, device_id=plexweb_device.id))
|
||||
== 0
|
||||
)
|
||||
assert (
|
||||
len(
|
||||
hass.helpers.entity_registry.async_entries_for_device(
|
||||
er.async_entries_for_device(
|
||||
entity_registry, device_id=non_plexweb_device.id
|
||||
)
|
||||
)
|
||||
|
@ -130,7 +122,7 @@ async def test_migrate_transient_devices(
|
|||
)
|
||||
assert (
|
||||
len(
|
||||
hass.helpers.entity_registry.async_entries_for_device(
|
||||
er.async_entries_for_device(
|
||||
entity_registry, device_id=plex_service_device.id
|
||||
)
|
||||
)
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
"""Tests for instance ID helper."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.helpers import instance_id
|
||||
|
||||
|
||||
async def test_get_id_empty(hass, hass_storage):
|
||||
"""Get unique ID."""
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
uuid = await instance_id.async_get(hass)
|
||||
assert uuid is not None
|
||||
# Assert it's stored
|
||||
assert hass_storage["core.uuid"]["data"]["uuid"] == uuid
|
||||
|
@ -15,7 +17,7 @@ async def test_get_id_migrate(hass, hass_storage):
|
|||
with patch(
|
||||
"homeassistant.util.json.load_json", return_value={"uuid": "1234"}
|
||||
), patch("os.path.isfile", return_value=True), patch("os.remove") as mock_remove:
|
||||
uuid = await hass.helpers.instance_id.async_get()
|
||||
uuid = await instance_id.async_get(hass)
|
||||
|
||||
assert uuid == "1234"
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from unittest.mock import Mock
|
|||
|
||||
from homeassistant.helpers.integration_platform import (
|
||||
async_process_integration_platform_for_component,
|
||||
async_process_integration_platforms,
|
||||
)
|
||||
from homeassistant.setup import ATTR_COMPONENT, EVENT_COMPONENT_LOADED
|
||||
|
||||
|
@ -24,8 +25,8 @@ async def test_process_integration_platforms(hass):
|
|||
"""Process platform."""
|
||||
processed.append((domain, platform))
|
||||
|
||||
await hass.helpers.integration_platform.async_process_integration_platforms(
|
||||
"platform_to_check", _process_platform
|
||||
await async_process_integration_platforms(
|
||||
hass, "platform_to_check", _process_platform
|
||||
)
|
||||
|
||||
assert len(processed) == 1
|
||||
|
@ -40,9 +41,7 @@ async def test_process_integration_platforms(hass):
|
|||
assert processed[1][1] == event_platform
|
||||
|
||||
# Verify we only process the platform once if we call it manually
|
||||
await hass.helpers.integration_platform.async_process_integration_platform_for_component(
|
||||
hass, "event"
|
||||
)
|
||||
await async_process_integration_platform_for_component(hass, "event")
|
||||
assert len(processed) == 2
|
||||
|
||||
|
||||
|
|
|
@ -3,11 +3,12 @@ import json
|
|||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.const import __version__ as current_version
|
||||
from homeassistant.helpers.system_info import async_get_system_info
|
||||
|
||||
|
||||
async def test_get_system_info(hass):
|
||||
"""Test the get system info."""
|
||||
info = await hass.helpers.system_info.async_get_system_info()
|
||||
info = await async_get_system_info(hass)
|
||||
assert isinstance(info, dict)
|
||||
assert info["version"] == current_version
|
||||
assert info["user"] is not None
|
||||
|
@ -19,18 +20,18 @@ async def test_container_installationtype(hass):
|
|||
with patch("platform.system", return_value="Linux"), patch(
|
||||
"os.path.isfile", return_value=True
|
||||
), patch("homeassistant.helpers.system_info.getuser", return_value="root"):
|
||||
info = await hass.helpers.system_info.async_get_system_info()
|
||||
info = await async_get_system_info(hass)
|
||||
assert info["installation_type"] == "Home Assistant Container"
|
||||
|
||||
with patch("platform.system", return_value="Linux"), patch(
|
||||
"os.path.isfile", side_effect=lambda file: file == "/.dockerenv"
|
||||
), patch("homeassistant.helpers.system_info.getuser", return_value="user"):
|
||||
info = await hass.helpers.system_info.async_get_system_info()
|
||||
info = await async_get_system_info(hass)
|
||||
assert info["installation_type"] == "Unsupported Third Party Container"
|
||||
|
||||
|
||||
async def test_getuser_keyerror(hass):
|
||||
"""Test getuser keyerror."""
|
||||
with patch("homeassistant.helpers.system_info.getuser", side_effect=KeyError):
|
||||
info = await hass.helpers.system_info.async_get_system_info()
|
||||
info = await async_get_system_info(hass)
|
||||
assert info["user"] is None
|
||||
|
|
Loading…
Add table
Reference in a new issue