Add async_entries_for_config_entry

This commit is contained in:
epenet
2024-05-27 09:56:50 +00:00
parent 425b1627df
commit 09e8ca7d0d
2 changed files with 17 additions and 8 deletions

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

@@ -397,7 +397,15 @@ _OBSOLETE_IMPORT: dict[str, list[ObsoleteImportMatch]] = {
# Black list of imports that should be using the namespace
_FORCE_NAMESPACE_IMPORT: dict[tuple[str, str], str] = {
("homeassistant.helpers.area_registry", "async_get"): "ar.async_get",
(
"homeassistant.helpers.device_registry",
"async_entries_for_config_entry",
): "dr.async_entries_for_config_entry",
("homeassistant.helpers.device_registry", "async_get"): "dr.async_get",
(
"homeassistant.helpers.entity_registry",
"async_entries_for_config_entry",
): "er.async_entries_for_config_entry",
("homeassistant.helpers.entity_registry", "async_get"): "er.async_get",
("homeassistant.helpers.issue_registry", "async_get"): "ir.async_get",
}
@@ -538,19 +546,16 @@ class HassImportsFormatChecker(BaseChecker):
args=(import_match.string, obsolete_import.reason),
)
for name in node.names:
if self._has_invalid_namespace_import(node, node.modname, name[0]):
return
self._has_invalid_namespace_import(node, node.modname, name[0])
def _has_invalid_namespace_import(
self, node: nodes.ImportFrom, module: str, name: str
) -> bool:
) -> None:
for key, value in _FORCE_NAMESPACE_IMPORT.items():
if module == key[0] and name == key[1]:
self.add_message(
"hass-helper-namespace-import", node=node, args=(name, value)
)
return True
return False
def register(linter: PyLinter) -> None: