Enforce namespace import in core (#118235)

This commit is contained in:
epenet 2024-05-27 14:03:00 +02:00 committed by GitHub
parent 9828a50dca
commit 97f6b578c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 47 additions and 55 deletions

View file

@ -8,7 +8,7 @@ import voluptuous as vol
from homeassistant.components import websocket_api
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.area_registry import async_get
from homeassistant.helpers import area_registry as ar
@callback
@ -29,7 +29,7 @@ def websocket_list_areas(
msg: dict[str, Any],
) -> None:
"""Handle list areas command."""
registry = async_get(hass)
registry = ar.async_get(hass)
connection.send_result(
msg["id"],
[entry.json_fragment for entry in registry.async_list_areas()],
@ -55,7 +55,7 @@ def websocket_create_area(
msg: dict[str, Any],
) -> None:
"""Create area command."""
registry = async_get(hass)
registry = ar.async_get(hass)
data = dict(msg)
data.pop("type")
@ -91,7 +91,7 @@ def websocket_delete_area(
msg: dict[str, Any],
) -> None:
"""Delete area command."""
registry = async_get(hass)
registry = ar.async_get(hass)
try:
registry.async_delete(msg["area_id"])
@ -121,7 +121,7 @@ def websocket_update_area(
msg: dict[str, Any],
) -> None:
"""Handle update area websocket command."""
registry = async_get(hass)
registry = ar.async_get(hass)
data = dict(msg)
data.pop("type")

View file

@ -11,11 +11,8 @@ from homeassistant.components import websocket_api
from homeassistant.components.websocket_api.decorators import require_admin
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.device_registry import (
DeviceEntry,
DeviceEntryDisabler,
async_get,
)
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.device_registry import DeviceEntry, DeviceEntryDisabler
@callback
@ -42,7 +39,7 @@ def websocket_list_devices(
msg: dict[str, Any],
) -> None:
"""Handle list devices command."""
registry = async_get(hass)
registry = dr.async_get(hass)
# Build start of response message
msg_json_prefix = (
f'{{"id":{msg["id"]},"type": "{websocket_api.const.TYPE_RESULT}",'
@ -80,7 +77,7 @@ def websocket_update_device(
msg: dict[str, Any],
) -> None:
"""Handle update device websocket command."""
registry = async_get(hass)
registry = dr.async_get(hass)
msg.pop("type")
msg_id = msg.pop("id")
@ -112,7 +109,7 @@ async def websocket_remove_config_entry_from_device(
msg: dict[str, Any],
) -> None:
"""Remove config entry from a device."""
registry = async_get(hass)
registry = dr.async_get(hass)
config_entry_id = msg["config_entry_id"]
device_id = msg["device_id"]

View file

@ -7,7 +7,8 @@ import voluptuous as vol
from homeassistant.components import websocket_api
from homeassistant.components.websocket_api.connection import ActiveConnection
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.floor_registry import FloorEntry, async_get
from homeassistant.helpers import floor_registry as fr
from homeassistant.helpers.floor_registry import FloorEntry
@callback
@ -30,7 +31,7 @@ def websocket_list_floors(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle list floors command."""
registry = async_get(hass)
registry = fr.async_get(hass)
connection.send_result(
msg["id"],
[_entry_dict(entry) for entry in registry.async_list_floors()],
@ -52,7 +53,7 @@ def websocket_create_floor(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Create floor command."""
registry = async_get(hass)
registry = fr.async_get(hass)
data = dict(msg)
data.pop("type")
@ -82,7 +83,7 @@ def websocket_delete_floor(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Delete floor command."""
registry = async_get(hass)
registry = fr.async_get(hass)
try:
registry.async_delete(msg["floor_id"])
@ -108,7 +109,7 @@ def websocket_update_floor(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle update floor websocket command."""
registry = async_get(hass)
registry = fr.async_get(hass)
data = dict(msg)
data.pop("type")

View file

@ -7,8 +7,8 @@ import voluptuous as vol
from homeassistant.components import websocket_api
from homeassistant.components.websocket_api.connection import ActiveConnection
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.label_registry import LabelEntry, async_get
from homeassistant.helpers import config_validation as cv, label_registry as lr
from homeassistant.helpers.label_registry import LabelEntry
SUPPORTED_LABEL_THEME_COLORS = {
"primary",
@ -60,7 +60,7 @@ def websocket_list_labels(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle list labels command."""
registry = async_get(hass)
registry = lr.async_get(hass)
connection.send_result(
msg["id"],
[_entry_dict(entry) for entry in registry.async_list_labels()],
@ -84,7 +84,7 @@ def websocket_create_label(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Create label command."""
registry = async_get(hass)
registry = lr.async_get(hass)
data = dict(msg)
data.pop("type")
@ -110,7 +110,7 @@ def websocket_delete_label(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Delete label command."""
registry = async_get(hass)
registry = lr.async_get(hass)
try:
registry.async_delete(msg["label_id"])
@ -138,7 +138,7 @@ def websocket_update_label(
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
) -> None:
"""Handle update label websocket command."""
registry = async_get(hass)
registry = lr.async_get(hass)
data = dict(msg)
data.pop("type")

View file

@ -45,13 +45,12 @@ from homeassistant.core import (
callback,
)
from homeassistant.data_entry_flow import BaseServiceInfo
from homeassistant.helpers import config_validation as cv, discovery_flow
from homeassistant.helpers.device_registry import (
CONNECTION_NETWORK_MAC,
DeviceRegistry,
async_get,
format_mac,
from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
discovery_flow,
)
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, format_mac
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.event import (
async_track_state_added_domain,
@ -243,7 +242,7 @@ class WatcherBase:
matchers = self._integration_matchers
registered_devices_domains = matchers.registered_devices_domains
dev_reg: DeviceRegistry = async_get(self.hass)
dev_reg = dr.async_get(self.hass)
if device := dev_reg.async_get_device(
connections={(CONNECTION_NETWORK_MAC, formatted_mac)}
):

View file

@ -15,8 +15,12 @@ import voluptuous as vol
from homeassistant.components import http, websocket_api
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, integration_platform
from homeassistant.helpers.device_registry import DeviceEntry, async_get
from homeassistant.helpers import (
config_validation as cv,
device_registry as dr,
integration_platform,
)
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.json import (
ExtendedJSONEncoder,
find_paths_unserializable_data,
@ -280,7 +284,7 @@ class DownloadDiagnosticsView(http.HomeAssistantView):
)
# Device diagnostics
dev_reg = async_get(hass)
dev_reg = dr.async_get(hass)
if sub_id is None:
return web.Response(status=HTTPStatus.BAD_REQUEST)

View file

@ -24,15 +24,12 @@ from homeassistant.helpers import (
config_validation as cv,
entity_registry as er,
event as ev,
issue_registry as ir,
template,
)
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import async_get_platforms
from homeassistant.helpers.issue_registry import (
async_delete_issue,
async_get as async_get_issue_registry,
)
from homeassistant.helpers.reload import async_integration_yaml_config
from homeassistant.helpers.service import async_register_admin_service
from homeassistant.helpers.typing import ConfigType
@ -186,14 +183,14 @@ async def _async_config_entry_updated(hass: HomeAssistant, entry: ConfigEntry) -
@callback
def _async_remove_mqtt_issues(hass: HomeAssistant, mqtt_data: MqttData) -> None:
"""Unregister open config issues."""
issue_registry = async_get_issue_registry(hass)
issue_registry = ir.async_get(hass)
open_issues = [
issue_id
for (domain, issue_id), issue_entry in issue_registry.issues.items()
if domain == DOMAIN and issue_entry.translation_key == "invalid_platform_config"
]
for issue in open_issues:
async_delete_issue(hass, DOMAIN, issue)
ir.async_delete_issue(hass, DOMAIN, issue)
async def async_check_config_schema(

View file

@ -9,13 +9,10 @@ import voluptuous as vol
from homeassistant import data_entry_flow
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.integration_platform import (
async_process_integration_platforms,
)
from homeassistant.helpers.issue_registry import (
async_delete_issue,
async_get as async_get_issue_registry,
)
from .const import DOMAIN
from .models import RepairsFlow, RepairsProtocol
@ -37,7 +34,7 @@ class ConfirmRepairFlow(RepairsFlow):
if user_input is not None:
return self.async_create_entry(data={})
issue_registry = async_get_issue_registry(self.hass)
issue_registry = ir.async_get(self.hass)
description_placeholders = None
if issue := issue_registry.async_get_issue(self.handler, self.issue_id):
description_placeholders = issue.translation_placeholders
@ -63,7 +60,7 @@ class RepairsFlowManager(data_entry_flow.FlowManager):
assert data and "issue_id" in data
issue_id = data["issue_id"]
issue_registry = async_get_issue_registry(self.hass)
issue_registry = ir.async_get(self.hass)
issue = issue_registry.async_get_issue(handler_key, issue_id)
if issue is None or not issue.is_fixable:
raise data_entry_flow.UnknownStep
@ -87,7 +84,7 @@ class RepairsFlowManager(data_entry_flow.FlowManager):
) -> data_entry_flow.FlowResult:
"""Complete a fix flow."""
if result.get("type") != data_entry_flow.FlowResultType.ABORT:
async_delete_issue(self.hass, flow.handler, flow.init_data["issue_id"])
ir.async_delete_issue(self.hass, flow.handler, flow.init_data["issue_id"])
if "result" not in result:
result["result"] = None
return result

View file

@ -15,14 +15,11 @@ from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.components.http.decorators import require_admin
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import Unauthorized
from homeassistant.helpers import issue_registry as ir
from homeassistant.helpers.data_entry_flow import (
FlowManagerIndexView,
FlowManagerResourceView,
)
from homeassistant.helpers.issue_registry import (
async_get as async_get_issue_registry,
async_ignore_issue,
)
from .const import DOMAIN
@ -50,7 +47,7 @@ def ws_get_issue_data(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
) -> None:
"""Fix an issue."""
issue_registry = async_get_issue_registry(hass)
issue_registry = ir.async_get(hass)
if not (issue := issue_registry.async_get_issue(msg["domain"], msg["issue_id"])):
connection.send_error(
msg["id"],
@ -74,7 +71,7 @@ def ws_ignore_issue(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
) -> None:
"""Fix an issue."""
async_ignore_issue(hass, msg["domain"], msg["issue_id"], msg["ignore"])
ir.async_ignore_issue(hass, msg["domain"], msg["issue_id"], msg["ignore"])
connection.send_result(msg["id"])
@ -89,7 +86,7 @@ def ws_list_issues(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg: dict[str, Any]
) -> None:
"""Return a list of issues."""
issue_registry = async_get_issue_registry(hass)
issue_registry = ir.async_get(hass)
issues = [
{
"breaks_in_ha_version": issue.breaks_in_ha_version,

View file

@ -1290,7 +1290,7 @@ async def test_reload_after_invalid_config(
) -> None:
"""Test reloading yaml config fails."""
with patch(
"homeassistant.components.mqtt.async_delete_issue"
"homeassistant.components.mqtt.ir.async_delete_issue"
) as mock_async_remove_issue:
assert await mqtt_mock_entry()
assert hass.states.get("alarm_control_panel.test") is None