Skip to content

Commit

Permalink
fix order of yaml loading
Browse files Browse the repository at this point in the history
  • Loading branch information
pszafer committed Jan 22, 2025
1 parent 1a5fd08 commit da3e60d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 11 additions & 5 deletions boneio/helper/yaml_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def merge_board_config(config: dict) -> dict:
f"Input mapping '{input['boneio_input']}' not found in board configuration"
)
# Merge mapped output with user config, preserving user-specified values
input.update({k: v for k, v in mapped_input.items() if k not in input})
input.update({k: v for k, v in mapped_input.items()})

for input in config.get("binary_sensor", []):
if "boneio_input" in input:
Expand All @@ -273,7 +273,7 @@ def merge_board_config(config: dict) -> dict:
f"Input mapping '{input['boneio_input']}' not found in board configuration"
)
# Merge mapped output with user config, preserving user-specified values
input.update({k: v for k, v in mapped_input.items() if k not in input})
input.update({k: v for k, v in mapped_input.items()})


return config
Expand Down Expand Up @@ -492,7 +492,13 @@ def load_config_from_string(config_str: str) -> dict:
schema = load_yaml_file(schema_file)
v = CustomValidator(schema, purge_unknown=True)

if not v.validate(config_str):
# First normalize the document
doc = v.normalized(config_str, always_return_document=True)
# Then merge board config
merged_doc = merge_board_config(doc)

# Finally validate
if not v.validate(merged_doc):
error_msg = "Configuration validation failed:\n"
for field, errors in v.errors.items():
error_lines = []
Expand All @@ -503,8 +509,8 @@ def load_config_from_string(config_str: str) -> dict:
]
error_msg += f"\n- {field}: {errors}\n{', '.join(error_lines)}"
raise ConfigurationException(error_msg)
doc = v.normalized(v.document, always_return_document=True)
return merge_board_config(doc)

return merged_doc


def load_config_from_file(config_file: str):
Expand Down
8 changes: 7 additions & 1 deletion boneio/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ binary_sensor:
boneio_input:
type: string
required: False
coerce:
- str
- lower
meta:
label: Reference to predefined input configuration
show_in_ha:
Expand Down Expand Up @@ -707,6 +710,9 @@ event:
boneio_input:
type: string
required: False
coerce:
- str
- lower
meta:
label: Reference to predefined input configuration
show_in_ha:
Expand Down Expand Up @@ -927,7 +933,7 @@ boneio:
device_type:
type: string
required: False
allowed: ['32x10A', '32x10', '32', '24x16A', '24x16', '24', 'cover', 'cover mix', 'cm']
allowed: ['32x10A', '32x10', '32', '24x16A', '24x16', '24', 'cover', 'cover mix', 'cm', '32x10a', '24x16a']
coerce:
- str
- lower
Expand Down
2 changes: 1 addition & 1 deletion boneio/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# flake8: noqa
__version__ = "0.9.0"
__version__ = "0.9.1"

0 comments on commit da3e60d

Please sign in to comment.