mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Include platform only integrations in the manifest list api (#48269)
This commit is contained in:
parent
e2d3c0ea8f
commit
1fb9008488
@ -221,7 +221,7 @@ class DeviceTrackerPlatform:
|
|||||||
|
|
||||||
async def async_setup_legacy(self, hass, tracker, discovery_info=None):
|
async def async_setup_legacy(self, hass, tracker, discovery_info=None):
|
||||||
"""Set up a legacy platform."""
|
"""Set up a legacy platform."""
|
||||||
LOGGER.info("Setting up %s.%s", DOMAIN, self.type)
|
LOGGER.info("Setting up %s.%s", DOMAIN, self.name)
|
||||||
try:
|
try:
|
||||||
scanner = None
|
scanner = None
|
||||||
setup = None
|
setup = None
|
||||||
@ -248,6 +248,9 @@ class DeviceTrackerPlatform:
|
|||||||
else:
|
else:
|
||||||
raise HomeAssistantError("Invalid legacy device_tracker platform.")
|
raise HomeAssistantError("Invalid legacy device_tracker platform.")
|
||||||
|
|
||||||
|
if setup:
|
||||||
|
hass.config.components.add(f"{DOMAIN}.{self.name}")
|
||||||
|
|
||||||
if scanner:
|
if scanner:
|
||||||
async_setup_scanner_platform(
|
async_setup_scanner_platform(
|
||||||
hass, self.config, scanner, tracker.async_see, self.type
|
hass, self.config, scanner, tracker.async_see, self.type
|
||||||
@ -255,11 +258,11 @@ class DeviceTrackerPlatform:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not setup:
|
if not setup:
|
||||||
LOGGER.error("Error setting up platform %s", self.type)
|
LOGGER.error("Error setting up platform %s %s", self.type, self.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
LOGGER.exception("Error setting up platform %s", self.type)
|
LOGGER.exception("Error setting up platform %s %s", self.type, self.name)
|
||||||
|
|
||||||
|
|
||||||
async def async_extract_config(hass, config):
|
async def async_extract_config(hass, config):
|
||||||
|
@ -17,6 +17,7 @@ from homeassistant.helpers import config_validation as cv, entity, template
|
|||||||
from homeassistant.helpers.event import TrackTemplate, async_track_template_result
|
from homeassistant.helpers.event import TrackTemplate, async_track_template_result
|
||||||
from homeassistant.helpers.service import async_get_all_descriptions
|
from homeassistant.helpers.service import async_get_all_descriptions
|
||||||
from homeassistant.loader import IntegrationNotFound, async_get_integration
|
from homeassistant.loader import IntegrationNotFound, async_get_integration
|
||||||
|
from homeassistant.setup import async_get_loaded_integrations
|
||||||
|
|
||||||
from . import const, decorators, messages
|
from . import const, decorators, messages
|
||||||
|
|
||||||
@ -215,13 +216,9 @@ def handle_get_config(hass, connection, msg):
|
|||||||
@decorators.async_response
|
@decorators.async_response
|
||||||
async def handle_manifest_list(hass, connection, msg):
|
async def handle_manifest_list(hass, connection, msg):
|
||||||
"""Handle integrations command."""
|
"""Handle integrations command."""
|
||||||
|
loaded_integrations = async_get_loaded_integrations(hass)
|
||||||
integrations = await asyncio.gather(
|
integrations = await asyncio.gather(
|
||||||
*[
|
*[async_get_integration(hass, domain) for domain in loaded_integrations]
|
||||||
async_get_integration(hass, domain)
|
|
||||||
for domain in hass.config.components
|
|
||||||
# Filter out platforms.
|
|
||||||
if "." not in domain
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
connection.send_result(
|
connection.send_result(
|
||||||
msg["id"], [integration.manifest for integration in integrations]
|
msg["id"], [integration.manifest for integration in integrations]
|
||||||
|
@ -18,6 +18,28 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
ATTR_COMPONENT = "component"
|
ATTR_COMPONENT = "component"
|
||||||
|
|
||||||
|
BASE_PLATFORMS = {
|
||||||
|
"air_quality",
|
||||||
|
"alarm_control_panel",
|
||||||
|
"binary_sensor",
|
||||||
|
"climate",
|
||||||
|
"cover",
|
||||||
|
"device_tracker",
|
||||||
|
"fan",
|
||||||
|
"humidifier",
|
||||||
|
"image_processing",
|
||||||
|
"light",
|
||||||
|
"lock",
|
||||||
|
"media_player",
|
||||||
|
"notify",
|
||||||
|
"remote",
|
||||||
|
"scene",
|
||||||
|
"sensor",
|
||||||
|
"switch",
|
||||||
|
"vacuum",
|
||||||
|
"water_heater",
|
||||||
|
}
|
||||||
|
|
||||||
DATA_SETUP_DONE = "setup_done"
|
DATA_SETUP_DONE = "setup_done"
|
||||||
DATA_SETUP_STARTED = "setup_started"
|
DATA_SETUP_STARTED = "setup_started"
|
||||||
DATA_SETUP = "setup_tasks"
|
DATA_SETUP = "setup_tasks"
|
||||||
@ -381,3 +403,17 @@ def async_when_setup(
|
|||||||
await when_setup()
|
await when_setup()
|
||||||
|
|
||||||
unsub = hass.bus.async_listen(EVENT_COMPONENT_LOADED, loaded_event)
|
unsub = hass.bus.async_listen(EVENT_COMPONENT_LOADED, loaded_event)
|
||||||
|
|
||||||
|
|
||||||
|
@core.callback
|
||||||
|
def async_get_loaded_integrations(hass: core.HomeAssistant) -> set:
|
||||||
|
"""Return the complete list of loaded integrations."""
|
||||||
|
integrations = set()
|
||||||
|
for component in hass.config.components:
|
||||||
|
if "." not in component:
|
||||||
|
integrations.add(component)
|
||||||
|
continue
|
||||||
|
domain, platform = component.split(".", 1)
|
||||||
|
if domain in BASE_PLATFORMS:
|
||||||
|
integrations.add(platform)
|
||||||
|
return integrations
|
||||||
|
@ -5,6 +5,7 @@ import ast
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from homeassistant.requirements import DISCOVERY_INTEGRATIONS
|
from homeassistant.requirements import DISCOVERY_INTEGRATIONS
|
||||||
|
from homeassistant.setup import BASE_PLATFORMS
|
||||||
|
|
||||||
from .model import Integration
|
from .model import Integration
|
||||||
|
|
||||||
@ -107,7 +108,6 @@ ALLOWED_USED_COMPONENTS = {
|
|||||||
"onboarding",
|
"onboarding",
|
||||||
"persistent_notification",
|
"persistent_notification",
|
||||||
"person",
|
"person",
|
||||||
"remote",
|
|
||||||
"script",
|
"script",
|
||||||
"shopping_list",
|
"shopping_list",
|
||||||
"sun",
|
"sun",
|
||||||
@ -118,22 +118,7 @@ ALLOWED_USED_COMPONENTS = {
|
|||||||
"websocket_api",
|
"websocket_api",
|
||||||
"zone",
|
"zone",
|
||||||
# Entity integrations with platforms
|
# Entity integrations with platforms
|
||||||
"alarm_control_panel",
|
*BASE_PLATFORMS,
|
||||||
"binary_sensor",
|
|
||||||
"climate",
|
|
||||||
"cover",
|
|
||||||
"device_tracker",
|
|
||||||
"fan",
|
|
||||||
"humidifier",
|
|
||||||
"image_processing",
|
|
||||||
"light",
|
|
||||||
"lock",
|
|
||||||
"media_player",
|
|
||||||
"scene",
|
|
||||||
"sensor",
|
|
||||||
"switch",
|
|
||||||
"vacuum",
|
|
||||||
"water_heater",
|
|
||||||
# Other
|
# Other
|
||||||
"mjpeg", # base class, has no reqs or component to load.
|
"mjpeg", # base class, has no reqs or component to load.
|
||||||
"stream", # Stream cannot install on all systems, can be imported without reqs.
|
"stream", # Stream cannot install on all systems, can be imported without reqs.
|
||||||
|
@ -600,3 +600,21 @@ async def test_integration_disabled(hass, caplog):
|
|||||||
result = await setup.async_setup_component(hass, "test_component1", {})
|
result = await setup.async_setup_component(hass, "test_component1", {})
|
||||||
assert not result
|
assert not result
|
||||||
assert disabled_reason in caplog.text
|
assert disabled_reason in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_get_loaded_integrations(hass):
|
||||||
|
"""Test we can enumerate loaded integations."""
|
||||||
|
hass.config.components.add("notbase")
|
||||||
|
hass.config.components.add("switch")
|
||||||
|
hass.config.components.add("notbase.switch")
|
||||||
|
hass.config.components.add("myintegration")
|
||||||
|
hass.config.components.add("device_tracker")
|
||||||
|
hass.config.components.add("device_tracker.other")
|
||||||
|
hass.config.components.add("myintegration.light")
|
||||||
|
assert setup.async_get_loaded_integrations(hass) == {
|
||||||
|
"other",
|
||||||
|
"switch",
|
||||||
|
"notbase",
|
||||||
|
"myintegration",
|
||||||
|
"device_tracker",
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user