Compare commits

...

2 Commits

Author SHA1 Message Date
Brett Adams
800cdee409
Update Diagnostics in Teslemetry (#138759)
* Testing

* Diag
2025-02-18 09:44:29 +01:00
Jan Bouwhuis
33df208296
Fix temp files of mqtt CI tests not cleaned up properly (#138741)
* Fix temp files of mqtt CI tests not cleaned up properly

* Do not cleanup tempfiles, patch gettempdir only
2025-02-18 08:38:43 +01:00
5 changed files with 52 additions and 7 deletions

View File

@ -35,7 +35,9 @@ async def async_get_config_entry_diagnostics(
vehicles = [ vehicles = [
{ {
"data": async_redact_data(x.coordinator.data, VEHICLE_REDACT), "data": async_redact_data(x.coordinator.data, VEHICLE_REDACT),
# Stream diag will go here when implemented "stream": {
"config": x.stream_vehicle.config,
},
} }
for x in entry.runtime_data.vehicles for x in entry.runtime_data.vehicles
] ]
@ -45,6 +47,7 @@ async def async_get_config_entry_diagnostics(
if x.live_coordinator if x.live_coordinator
else None, else None,
"info": async_redact_data(x.info_coordinator.data, ENERGY_INFO_REDACT), "info": async_redact_data(x.info_coordinator.data, ENERGY_INFO_REDACT),
"history": x.history_coordinator.data if x.history_coordinator else None,
} }
for x in entry.runtime_data.energysites for x in entry.runtime_data.energysites
] ]

View File

@ -2,6 +2,7 @@
import asyncio import asyncio
from collections.abc import AsyncGenerator, Generator from collections.abc import AsyncGenerator, Generator
from pathlib import Path
from random import getrandbits from random import getrandbits
from typing import Any from typing import Any
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
@ -39,13 +40,22 @@ def temp_dir_prefix() -> str:
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def mock_temp_dir(temp_dir_prefix: str) -> Generator[str]: async def mock_temp_dir(
hass: HomeAssistant, tmp_path: Path, temp_dir_prefix: str
) -> AsyncGenerator[str]:
"""Mock the certificate temp directory.""" """Mock the certificate temp directory."""
with patch( mqtt_temp_dir = f"home-assistant-mqtt-{temp_dir_prefix}-{getrandbits(10):03x}"
# Patch temp dir name to avoid tests fail running in parallel with (
"homeassistant.components.mqtt.util.TEMP_DIR_NAME", patch(
f"home-assistant-mqtt-{temp_dir_prefix}-{getrandbits(10):03x}", "homeassistant.components.mqtt.util.tempfile.gettempdir",
) as mocked_temp_dir: return_value=tmp_path,
),
patch(
# Patch temp dir name to avoid tests fail running in parallel
"homeassistant.components.mqtt.util.TEMP_DIR_NAME",
mqtt_temp_dir,
) as mocked_temp_dir,
):
yield mocked_temp_dir yield mocked_temp_dir

View File

@ -1034,6 +1034,7 @@ async def test_reloadable(
await help_test_reloadable(hass, mqtt_client_mock, domain, config) await help_test_reloadable(hass, mqtt_client_mock, domain, config)
@pytest.mark.usefixtures("mock_temp_dir")
@pytest.mark.parametrize( @pytest.mark.parametrize(
("hass_config", "payload1", "state1", "payload2", "state2"), ("hass_config", "payload1", "state1", "payload2", "state2"),
[ [

View File

@ -1409,6 +1409,7 @@ async def test_reloadable(
await help_test_reloadable(hass, mqtt_client_mock, domain, config) await help_test_reloadable(hass, mqtt_client_mock, domain, config)
@pytest.mark.usefixtures("mock_temp_dir")
@pytest.mark.parametrize( @pytest.mark.parametrize(
"hass_config", "hass_config",
[ [

View File

@ -3,6 +3,29 @@
dict({ dict({
'energysites': list([ 'energysites': list([
dict({ dict({
'history': dict({
'battery_energy_exported': 36,
'battery_energy_imported_from_generator': 0,
'battery_energy_imported_from_grid': 0,
'battery_energy_imported_from_solar': 684,
'consumer_energy_imported_from_battery': 36,
'consumer_energy_imported_from_generator': 0,
'consumer_energy_imported_from_grid': 0,
'consumer_energy_imported_from_solar': 38,
'generator_energy_exported': 0,
'grid_energy_exported_from_battery': 0,
'grid_energy_exported_from_generator': 0,
'grid_energy_exported_from_solar': 2,
'grid_energy_imported': 0,
'grid_services_energy_exported': 0,
'grid_services_energy_imported': 0,
'solar_energy_exported': 724,
'total_battery_charge': 684,
'total_battery_discharge': 36,
'total_grid_energy_exported': 2,
'total_home_usage': 74,
'total_solar_generation': 724,
}),
'info': dict({ 'info': dict({
'backup_reserve_percent': 0, 'backup_reserve_percent': 0,
'battery_count': 2, 'battery_count': 2,
@ -432,6 +455,13 @@
'vehicle_state_webcam_available': True, 'vehicle_state_webcam_available': True,
'vin': '**REDACTED**', 'vin': '**REDACTED**',
}), }),
'stream': dict({
'config': dict({
'fields': dict({
}),
'prefer_typed': None,
}),
}),
}), }),
]), ]),
}) })