Submit legacy integrations for analytics (#145787)
* Submit legacy integrations for analytics * adjustmentspull/146029/head
parent
a2b2f6f20a
commit
ad493e077e
|
@ -24,7 +24,7 @@ from homeassistant.components.recorder import (
|
|||
get_instance as get_recorder_instance,
|
||||
)
|
||||
from homeassistant.config_entries import SOURCE_IGNORE
|
||||
from homeassistant.const import ATTR_DOMAIN, __version__ as HA_VERSION
|
||||
from homeassistant.const import ATTR_DOMAIN, BASE_PLATFORMS, __version__ as HA_VERSION
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
@ -225,7 +225,8 @@ class Analytics:
|
|||
LOGGER.error(err)
|
||||
return
|
||||
|
||||
configuration_set = set(yaml_configuration)
|
||||
configuration_set = _domains_from_yaml_config(yaml_configuration)
|
||||
|
||||
er_platforms = {
|
||||
entity.platform
|
||||
for entity in ent_reg.entities.values()
|
||||
|
@ -370,3 +371,13 @@ class Analytics:
|
|||
for entry in entries
|
||||
if entry.source != SOURCE_IGNORE and entry.disabled_by is None
|
||||
)
|
||||
|
||||
|
||||
def _domains_from_yaml_config(yaml_configuration: dict[str, Any]) -> set[str]:
|
||||
"""Extract domains from the YAML configuration."""
|
||||
domains = set(yaml_configuration)
|
||||
for platforms in conf_util.extract_platform_integrations(
|
||||
yaml_configuration, BASE_PLATFORMS
|
||||
).values():
|
||||
domains.update(platforms)
|
||||
return domains
|
||||
|
|
|
@ -222,3 +222,16 @@
|
|||
'version': '1970.1.0',
|
||||
})
|
||||
# ---
|
||||
# name: test_submitting_legacy_integrations
|
||||
dict({
|
||||
'certificate': False,
|
||||
'custom_integrations': list([
|
||||
]),
|
||||
'installation_type': 'Home Assistant Tests',
|
||||
'integrations': list([
|
||||
'legacy_binary_sensor',
|
||||
]),
|
||||
'uuid': 'abcdefg',
|
||||
'version': '1970.1.0',
|
||||
})
|
||||
# ---
|
||||
|
|
|
@ -920,3 +920,49 @@ async def test_not_check_config_entries_if_yaml(
|
|||
assert submitted_data["integrations"] == ["default_config"]
|
||||
assert submitted_data == logged_data
|
||||
assert snapshot == submitted_data
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("installation_type_mock", "supervisor_client")
|
||||
async def test_submitting_legacy_integrations(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test submitting legacy integrations."""
|
||||
hass.http = Mock(ssl_certificate=None)
|
||||
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
|
||||
analytics = Analytics(hass)
|
||||
|
||||
await analytics.save_preferences({ATTR_BASE: True, ATTR_USAGE: True})
|
||||
assert analytics.preferences[ATTR_BASE]
|
||||
assert analytics.preferences[ATTR_USAGE]
|
||||
hass.config.components = ["binary_sensor"]
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.analytics.analytics.async_get_integrations",
|
||||
return_value={
|
||||
"default_config": mock_integration(
|
||||
hass,
|
||||
MockModule(
|
||||
"legacy_binary_sensor",
|
||||
async_setup=AsyncMock(return_value=True),
|
||||
partial_manifest={"config_flow": False},
|
||||
),
|
||||
),
|
||||
},
|
||||
),
|
||||
patch(
|
||||
"homeassistant.config.async_hass_config_yaml",
|
||||
return_value={"binary_sensor": [{"platform": "legacy_binary_sensor"}]},
|
||||
),
|
||||
):
|
||||
await analytics.send_analytics()
|
||||
|
||||
logged_data = caplog.records[-1].args
|
||||
submitted_data = _last_call_payload(aioclient_mock)
|
||||
|
||||
assert submitted_data["integrations"] == ["legacy_binary_sensor"]
|
||||
assert submitted_data == logged_data
|
||||
assert snapshot == submitted_data
|
||||
|
|
Loading…
Reference in New Issue