Skip to content

Commit

Permalink
add missed fnc wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Oct 30, 2024
1 parent b7d9225 commit 6b8689f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/evohomeasync2/schema/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/tests/test_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 8 additions & 5 deletions tests/tests/test_schemas_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
SZ_TEMPERATURE_CONTROL_SYSTEMS,
SZ_TIME_ZONE,
)
from evohomeasync2.schema.helpers import snake_to_camel

from .helpers import TEST_DIR

Expand Down Expand Up @@ -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)


Expand All @@ -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)
26 changes: 15 additions & 11 deletions tests/tests/test_schemas_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
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,
SZ_LOCATION_INFO,
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
Expand Down Expand Up @@ -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:
Expand All @@ -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)


Expand All @@ -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)

0 comments on commit 6b8689f

Please sign in to comment.