Add Homeassistant Analytics Insights integration (#107634)

* Add Homeassistant Analytics integration

* Add Homeassistant Analytics integration

* Add Homeassistant Analytics integration

* Fix feedback

* Fix test

* Update conftest.py

* Add some testcases

* Make code clear

* log exception

* Bump python-homeassistant-analytics to 0.2.1

* Bump python-homeassistant-analytics to 0.3.0

* Change domain to homeassistant_analytics_consumer

* Add integration name to config flow selector

* Update homeassistant/components/homeassistant_analytics_consumer/manifest.json

Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>

* Fix hassfest

* Apply suggestions from code review

Co-authored-by: Robert Resch <robert@resch.dev>

* Bump python-homeassistant-analytics to 0.4.0

* Rename to Home Assistant Analytics Insights

* Update homeassistant/components/analytics_insights/config_flow.py

Co-authored-by: Robert Resch <robert@resch.dev>

* Update homeassistant/components/analytics_insights/manifest.json

Co-authored-by: Robert Resch <robert@resch.dev>

* Rename to Home Assistant Analytics Insights

* add test

* Fallback to 0 when there is no data found

* Allow to select any integration

* Fix tests

* Fix tests

* Update tests/components/analytics_insights/conftest.py

Co-authored-by: Robert Resch <robert@resch.dev>

* Update tests/components/analytics_insights/test_sensor.py

Co-authored-by: Robert Resch <robert@resch.dev>

* Fix format

* Fix tests

---------

Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
Joost Lekkerkerker 2024-01-23 10:32:31 +01:00 committed by GitHub
parent 52ede95c4f
commit d9f1450ee6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 3226 additions and 0 deletions

View file

@ -0,0 +1,54 @@
"""Common fixtures for the Homeassistant Analytics tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
import pytest
from python_homeassistant_analytics import CurrentAnalytics
from python_homeassistant_analytics.models import Integration
from homeassistant.components.analytics_insights import DOMAIN
from homeassistant.components.analytics_insights.const import CONF_TRACKED_INTEGRATIONS
from tests.common import MockConfigEntry, load_fixture, load_json_object_fixture
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.analytics_insights.async_setup_entry",
return_value=True,
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_analytics_client() -> Generator[AsyncMock, None, None]:
"""Mock a Homeassistant Analytics client."""
with patch(
"homeassistant.components.analytics_insights.HomeassistantAnalyticsClient",
autospec=True,
) as mock_client, patch(
"homeassistant.components.analytics_insights.config_flow.HomeassistantAnalyticsClient",
new=mock_client,
):
client = mock_client.return_value
client.get_current_analytics.return_value = CurrentAnalytics.from_json(
load_fixture("analytics_insights/current_data.json")
)
integrations = load_json_object_fixture("analytics_insights/integrations.json")
client.get_integrations.return_value = {
key: Integration.from_dict(value) for key, value in integrations.items()
}
yield client
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Mock a config entry."""
return MockConfigEntry(
domain=DOMAIN,
title="Homeassistant Analytics",
data={},
options={CONF_TRACKED_INTEGRATIONS: ["youtube", "spotify", "myq"]},
)