core/tests/components/bsblan/test_diagnostics.py

27 lines
747 B
Python
Raw Normal View History

"""Tests for the diagnostics data provided by the BSBLan integration."""
Add tests for BSBLAN climate component (#124524) * chore: Add tests for BSBLAN climate component * fix return types * fix MAC data * chore: Update BSBLAN climate component tests used setup from conftest added setup for farhenheit temp unit * chore: Update BSBLAN climate component tests use syrupy to compare results * add test for temp_unit * update climate tests set current_temperature to None in test case. Is this the correct way for testing? * chore: Update BSBLAN diagnostics to handle asynchronous data retrieval * chore: Refactor BSBLAN conftest.py to simplify fixture and patching * chore: Update BSBLAN climate component tests 100% test coverage * chore: Update BSBLAN diagnostics to handle asynchronous data retrieval * chore: Update snapshots * Fix BSBLAN climate test for async_set_preset_mode - Update test_async_set_preset_mode to correctly handle ServiceValidationError - Check for specific translation key instead of full error message - Ensure consistency between local tests and CI environment - Import ServiceValidationError explicitly for clarity * Update homeassistant/components/bsblan/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * chore: Update BSBLAN conftest.py to simplify fixture and patching * chore: Update BSBLAN integration setup function parameter name * chore: removed set_static_value * refactor: Improve BSBLANClimate async_set_preset_mode method This commit refactors the async_set_preset_mode method in the BSBLANClimate class to improve code readability and maintainability. The method now checks if the HVAC mode is not set to AUTO and the preset mode is not NONE before raising a ServiceValidationError. Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * refactor: Improve tests test_celsius_fahrenheit test_climate_entity_properties test_async_set_hvac_mode test_async_set_preset_mode still broken. Not sure why hvac mode will not set. THis causes error with preset mode set * update snapshot * fix DOMAIN bsblan * refactor: Improve BSBLANClimate async_set_data method * refactor: fix last tests * refactor: Simplify async_get_config_entry_diagnostics method * refactor: Improve BSBLANClimate async_set_temperature method This commit improves the async_set_temperature method in the BSBLANClimate class. It removes the unnecessary parameter "expected_result" and simplifies the code by directly calling the service to set the temperature. The method now correctly asserts that the thermostat method is called with the correct temperature. * refactor: Add static data to async_get_config_entry_diagnostics * refactor: Add static data to async_get_config_entry_diagnostics right place * refactor: Improve error message for setting preset mode This commit updates the error message in the BSBLANClimate class when trying to set the preset mode. * refactor: Improve tests * Fix --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-08 08:41:54 +00:00
from unittest.mock import AsyncMock
from syrupy import SnapshotAssertion
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_diagnostics(
hass: HomeAssistant,
Add tests for BSBLAN climate component (#124524) * chore: Add tests for BSBLAN climate component * fix return types * fix MAC data * chore: Update BSBLAN climate component tests used setup from conftest added setup for farhenheit temp unit * chore: Update BSBLAN climate component tests use syrupy to compare results * add test for temp_unit * update climate tests set current_temperature to None in test case. Is this the correct way for testing? * chore: Update BSBLAN diagnostics to handle asynchronous data retrieval * chore: Refactor BSBLAN conftest.py to simplify fixture and patching * chore: Update BSBLAN climate component tests 100% test coverage * chore: Update BSBLAN diagnostics to handle asynchronous data retrieval * chore: Update snapshots * Fix BSBLAN climate test for async_set_preset_mode - Update test_async_set_preset_mode to correctly handle ServiceValidationError - Check for specific translation key instead of full error message - Ensure consistency between local tests and CI environment - Import ServiceValidationError explicitly for clarity * Update homeassistant/components/bsblan/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * chore: Update BSBLAN conftest.py to simplify fixture and patching * chore: Update BSBLAN integration setup function parameter name * chore: removed set_static_value * refactor: Improve BSBLANClimate async_set_preset_mode method This commit refactors the async_set_preset_mode method in the BSBLANClimate class to improve code readability and maintainability. The method now checks if the HVAC mode is not set to AUTO and the preset mode is not NONE before raising a ServiceValidationError. Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * refactor: Improve tests test_celsius_fahrenheit test_climate_entity_properties test_async_set_hvac_mode test_async_set_preset_mode still broken. Not sure why hvac mode will not set. THis causes error with preset mode set * update snapshot * fix DOMAIN bsblan * refactor: Improve BSBLANClimate async_set_data method * refactor: fix last tests * refactor: Simplify async_get_config_entry_diagnostics method * refactor: Improve BSBLANClimate async_set_temperature method This commit improves the async_set_temperature method in the BSBLANClimate class. It removes the unnecessary parameter "expected_result" and simplifies the code by directly calling the service to set the temperature. The method now correctly asserts that the thermostat method is called with the correct temperature. * refactor: Add static data to async_get_config_entry_diagnostics * refactor: Add static data to async_get_config_entry_diagnostics right place * refactor: Improve error message for setting preset mode This commit updates the error message in the BSBLANClimate class when trying to set the preset mode. * refactor: Improve tests * Fix --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-08 08:41:54 +00:00
mock_bsblan: AsyncMock,
hass_client: ClientSessionGenerator,
init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics."""
Add tests for BSBLAN climate component (#124524) * chore: Add tests for BSBLAN climate component * fix return types * fix MAC data * chore: Update BSBLAN climate component tests used setup from conftest added setup for farhenheit temp unit * chore: Update BSBLAN climate component tests use syrupy to compare results * add test for temp_unit * update climate tests set current_temperature to None in test case. Is this the correct way for testing? * chore: Update BSBLAN diagnostics to handle asynchronous data retrieval * chore: Refactor BSBLAN conftest.py to simplify fixture and patching * chore: Update BSBLAN climate component tests 100% test coverage * chore: Update BSBLAN diagnostics to handle asynchronous data retrieval * chore: Update snapshots * Fix BSBLAN climate test for async_set_preset_mode - Update test_async_set_preset_mode to correctly handle ServiceValidationError - Check for specific translation key instead of full error message - Ensure consistency between local tests and CI environment - Import ServiceValidationError explicitly for clarity * Update homeassistant/components/bsblan/entity.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * chore: Update BSBLAN conftest.py to simplify fixture and patching * chore: Update BSBLAN integration setup function parameter name * chore: removed set_static_value * refactor: Improve BSBLANClimate async_set_preset_mode method This commit refactors the async_set_preset_mode method in the BSBLANClimate class to improve code readability and maintainability. The method now checks if the HVAC mode is not set to AUTO and the preset mode is not NONE before raising a ServiceValidationError. Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * refactor: Improve tests test_celsius_fahrenheit test_climate_entity_properties test_async_set_hvac_mode test_async_set_preset_mode still broken. Not sure why hvac mode will not set. THis causes error with preset mode set * update snapshot * fix DOMAIN bsblan * refactor: Improve BSBLANClimate async_set_data method * refactor: fix last tests * refactor: Simplify async_get_config_entry_diagnostics method * refactor: Improve BSBLANClimate async_set_temperature method This commit improves the async_set_temperature method in the BSBLANClimate class. It removes the unnecessary parameter "expected_result" and simplifies the code by directly calling the service to set the temperature. The method now correctly asserts that the thermostat method is called with the correct temperature. * refactor: Add static data to async_get_config_entry_diagnostics * refactor: Add static data to async_get_config_entry_diagnostics right place * refactor: Improve error message for setting preset mode This commit updates the error message in the BSBLANClimate class when trying to set the preset mode. * refactor: Improve tests * Fix --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-09-08 08:41:54 +00:00
Refactor bsblan coordinator (#124308) * chore: Refactor BSBLanUpdateCoordinator to improve code readability and maintainability * feat: Add BSBLan integration models This commit adds the models for the BSB-Lan integration. It includes a dataclass for the BSBLanCoordinatorData, which stores the state and sensor information. * refactor: Update BSBLANClimate class to use DataUpdateCoordinator without specifying the State type * chore: Remove unused Sensor import in BSBLan models * feat: Refactor BSBLanEntity to use CoordinatorEntity The BSBLanEntity class has been refactored to inherit from the CoordinatorEntity class, which provides better integration with the update coordinator. This change improves code readability and maintainability. * refactor: Remove unused config_entry variable in BSBLanUpdateCoordinator * refactor: Update BSBLANClimate class to use DataUpdateCoordinator Refactor the BSBLANClimate class to use the Coordinator of the entity * refactor: Update tests to use the new structure * fix coverage it should be the same as before * refactor: moved dataclass BSBLanCoordinatorData * use the data class inside init * refactor: Remove unused config_entry variable in BSBLanUpdateCoordinator * refactor: use BSBLanData from init * remove entry data from diagnostics * fix: add random interval back * refactor: Simplify coordinator_data assignment in async_get_config_entry_diagnostics * revert back to original except dataclass import * revert: Add MAC address back to device info in BSBLanEntity
2024-08-23 06:42:36 +00:00
diagnostics_data = await get_diagnostics_for_config_entry(
hass, hass_client, init_integration
)
Refactor bsblan coordinator (#124308) * chore: Refactor BSBLanUpdateCoordinator to improve code readability and maintainability * feat: Add BSBLan integration models This commit adds the models for the BSB-Lan integration. It includes a dataclass for the BSBLanCoordinatorData, which stores the state and sensor information. * refactor: Update BSBLANClimate class to use DataUpdateCoordinator without specifying the State type * chore: Remove unused Sensor import in BSBLan models * feat: Refactor BSBLanEntity to use CoordinatorEntity The BSBLanEntity class has been refactored to inherit from the CoordinatorEntity class, which provides better integration with the update coordinator. This change improves code readability and maintainability. * refactor: Remove unused config_entry variable in BSBLanUpdateCoordinator * refactor: Update BSBLANClimate class to use DataUpdateCoordinator Refactor the BSBLANClimate class to use the Coordinator of the entity * refactor: Update tests to use the new structure * fix coverage it should be the same as before * refactor: moved dataclass BSBLanCoordinatorData * use the data class inside init * refactor: Remove unused config_entry variable in BSBLanUpdateCoordinator * refactor: use BSBLanData from init * remove entry data from diagnostics * fix: add random interval back * refactor: Simplify coordinator_data assignment in async_get_config_entry_diagnostics * revert back to original except dataclass import * revert: Add MAC address back to device info in BSBLanEntity
2024-08-23 06:42:36 +00:00
assert diagnostics_data == snapshot