mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Submit legacy integrations for analytics (#145787)
* Submit legacy integrations for analytics * adjustments
This commit is contained in:
parent
a2b2f6f20a
commit
ad493e077e
@ -24,7 +24,7 @@ from homeassistant.components.recorder import (
|
|||||||
get_instance as get_recorder_instance,
|
get_instance as get_recorder_instance,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IGNORE
|
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.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
@ -225,7 +225,8 @@ class Analytics:
|
|||||||
LOGGER.error(err)
|
LOGGER.error(err)
|
||||||
return
|
return
|
||||||
|
|
||||||
configuration_set = set(yaml_configuration)
|
configuration_set = _domains_from_yaml_config(yaml_configuration)
|
||||||
|
|
||||||
er_platforms = {
|
er_platforms = {
|
||||||
entity.platform
|
entity.platform
|
||||||
for entity in ent_reg.entities.values()
|
for entity in ent_reg.entities.values()
|
||||||
@ -370,3 +371,13 @@ class Analytics:
|
|||||||
for entry in entries
|
for entry in entries
|
||||||
if entry.source != SOURCE_IGNORE and entry.disabled_by is None
|
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',
|
'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["integrations"] == ["default_config"]
|
||||||
assert submitted_data == logged_data
|
assert submitted_data == logged_data
|
||||||
assert snapshot == submitted_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…
x
Reference in New Issue
Block a user