diff --git a/src/evohomeasync2/schema/config.py b/src/evohomeasync2/schema/config.py index d1dc7efe..240aee66 100644 --- a/src/evohomeasync2/schema/config.py +++ b/src/evohomeasync2/schema/config.py @@ -190,7 +190,7 @@ def _factory_zone(fnc: Callable[[str], str] = do_nothing) -> vol.Schema: SCH_FAN_MODE: Final = vol.Schema( # noqa: F841 { - vol.Required(SZ_FAN_MODE): vol.In([m.value for m in FanMode]), + vol.Required(fnc(SZ_FAN_MODE)): vol.In([m.value for m in FanMode]), }, extra=vol.PREVENT_EXTRA, ) diff --git a/tests/tests/helpers.py b/tests/tests/helpers.py index efd1af48..65744f27 100644 --- a/tests/tests/helpers.py +++ b/tests/tests/helpers.py @@ -18,7 +18,7 @@ def test_schema(folder: Path, schema: vol.Schema, file_name: str) -> None: pytest.skip(f"No {file_name} in: {folder.name}") with open(Path(folder).joinpath(file_name)) as f: - data: dict = json.load(f) + data: dict = json.load(f) # is camelCase, as per vendor's schema _ = schema(data) diff --git a/tests/tests/test_schedules.py b/tests/tests/test_schedules.py index fe34e809..297e0b3a 100644 --- a/tests/tests/test_schedules.py +++ b/tests/tests/test_schedules.py @@ -25,7 +25,7 @@ def _test_schedule_schema(file_name: str, schema: vol.Schema) -> dict: def read_dict_from_file(file_name: str) -> dict: with open(WORK_DIR.joinpath(file_name)) as f: - data: dict = json.load(f) + data: dict = json.load(f) # is camelCase, as per vendor's schema return data return schema(read_dict_from_file(file_name)) # type: ignore[no-any-return] diff --git a/tests/tests/test_schemas_0.py b/tests/tests/test_schemas_0.py index a4cba271..b6cb0349 100644 --- a/tests/tests/test_schemas_0.py +++ b/tests/tests/test_schemas_0.py @@ -25,6 +25,7 @@ SZ_TEMPERATURE_CONTROL_SYSTEMS, SZ_TIME_ZONE, ) +from evohomeasync2.schema.helpers import snake_to_camel from .helpers import TEST_DIR @@ -96,11 +97,13 @@ def test_config_schemas(folder: Path) -> None: pytest.skip(f"No {CONFIG_FILE_NAME} in: {folder.name}") with open(Path(folder).joinpath(CONFIG_FILE_NAME)) as f: - config: dict = json.load(f) + config: dict = json.load(f) # is camelCase, as per vendor's schema - _ = SCH_TIME_ZONE(config[SZ_LOCATION_INFO][SZ_TIME_ZONE]) - for gwy_config in config[SZ_GATEWAYS]: - for tcs_config in gwy_config[SZ_TEMPERATURE_CONTROL_SYSTEMS]: + _ = SCH_TIME_ZONE( + config[snake_to_camel(SZ_LOCATION_INFO)][snake_to_camel(SZ_TIME_ZONE)] + ) + for gwy_config in config[snake_to_camel(SZ_GATEWAYS)]: + for tcs_config in gwy_config[snake_to_camel(SZ_TEMPERATURE_CONTROL_SYSTEMS)]: _ = SCH_TCS_CONFIG(tcs_config) @@ -111,6 +114,6 @@ def test_status_schemas(folder: Path) -> None: pytest.skip(f"No {STATUS_FILE_NAME} in: {folder.name}") with open(Path(folder).joinpath(STATUS_FILE_NAME)) as f: - status: dict = json.load(f) + status: dict = json.load(f) # is camelCase, as per vendor's schema _ = SCH_LOCN_STATUS(status) diff --git a/tests/tests/test_schemas_1.py b/tests/tests/test_schemas_1.py index 19cb8158..d090e140 100644 --- a/tests/tests/test_schemas_1.py +++ b/tests/tests/test_schemas_1.py @@ -9,7 +9,7 @@ import pytest from evohomeasync2 import Location -from evohomeasync2.schema import SCH_LOCN_STATUS +from evohomeasync2.schema import SCH_LOCN_STATUS, convert_keys_to_snake_case from evohomeasync2.schema.config import SCH_TCS_CONFIG, SCH_TIME_ZONE from evohomeasync2.schema.const import ( SZ_GATEWAYS, @@ -17,7 +17,7 @@ SZ_TEMPERATURE_CONTROL_SYSTEMS, SZ_TIME_ZONE, ) -from evohomeasync2.session import convert_keys_to_snake_case +from evohomeasync2.schema.helpers import snake_to_camel from .conftest import ClientStub from .helpers import TEST_DIR @@ -49,13 +49,14 @@ def test_config_refresh(folder: Path) -> None: pytest.skip(f"No {STATUS_FILE_NAME} in: {folder.name}") with open(Path(folder).joinpath(CONFIG_FILE_NAME)) as f: - config: dict = convert_keys_to_snake_case(json.load(f)) + config: dict = json.load(f) # is camelCase, as per vendor's schema with open(Path(folder).joinpath(STATUS_FILE_NAME)) as f: - status: dict = convert_keys_to_snake_case(json.load(f)) + status: dict = json.load(f) # is camelCase, as per vendor's schema - loc = Location(ClientStub(), config) - loc._update_status(status) + # for this, we need snake_case keys + loc = Location(ClientStub(), convert_keys_to_snake_case(config)) + loc._update_status(convert_keys_to_snake_case(status)) def test_config_schemas(folder: Path) -> None: @@ -65,11 +66,14 @@ def test_config_schemas(folder: Path) -> None: pytest.skip(f"No {CONFIG_FILE_NAME} in: {folder.name}") with open(Path(folder).joinpath(CONFIG_FILE_NAME)) as f: - config: dict = json.load(f) + config: dict = json.load(f) # is camelCase, as per vendor's schema - _ = SCH_TIME_ZONE(config[SZ_LOCATION_INFO][SZ_TIME_ZONE]) - for gwy_config in config[SZ_GATEWAYS]: - for tcs_config in gwy_config[SZ_TEMPERATURE_CONTROL_SYSTEMS]: + _ = SCH_TIME_ZONE( + config[snake_to_camel(SZ_LOCATION_INFO)][snake_to_camel(SZ_TIME_ZONE)] + ) + + for gwy_config in (config[snake_to_camel(SZ_GATEWAYS)]): + for tcs_config in gwy_config[snake_to_camel(SZ_TEMPERATURE_CONTROL_SYSTEMS)]: _ = SCH_TCS_CONFIG(tcs_config) @@ -80,6 +84,6 @@ def test_status_schemas(folder: Path) -> None: pytest.skip(f"No {STATUS_FILE_NAME} in: {folder.name}") with open(Path(folder).joinpath(STATUS_FILE_NAME)) as f: - status: dict = json.load(f) + status: dict = json.load(f) # is camelCase, as per vendor's schema _ = SCH_LOCN_STATUS(status)