Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in serializing BooleanSetting to and from YAML #23

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Version 0.7.0 unreleased
* Move configuration into pyproject.toml for pytest, mypy & coverage.
* Upgrade to gha-shared-workflows@v8 for Poetry v2 support.
* Migrate from pendulum to arrow for dates (interface change).
* Fix bug in serializing BooleanSetting to and from YAML.
* Update all dependencies and outdated constraints.

Version 0.6.9 02 Jan 2025
Expand Down
6 changes: 6 additions & 0 deletions src/smartapp/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Converter to serialize and deserialize lifecycle objects to various formats.
"""
import json
from enum import Enum
from typing import Any, Dict, Type, TypeVar

import yaml
Expand All @@ -15,6 +16,7 @@
from attrs import fields, has
from cattrs import GenConverter
from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn, override
from yaml import SafeDumper

from .interface import (
CONFIG_SETTING_BY_TYPE,
Expand All @@ -41,6 +43,10 @@
T = TypeVar("T") # pylint: disable=invalid-name:


# Configure SafeDumper to handle Enum values
yaml.add_multi_representer(Enum, lambda d, e: d.represent_str(e.value), Dumper=SafeDumper)


def serialize_datetime(datetime: Arrow) -> str:
"""Serialize an Arrow datetime to a string."""
# Note that we always use the full millisecond timestamp here and always convert to UTC
Expand Down
2 changes: 1 addition & 1 deletion tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_boolean(self, settings):
name="True or false?",
description="Tap to set",
required=True,
default_value="true",
default_value=BooleanValue.TRUE,
)
validate_json_roundtrip(json, expected, BooleanSetting)
validate_yaml_roundtrip(None, expected, BooleanSetting)
Expand Down
Loading