Skip to content

Conversation

@Lash-L
Copy link
Collaborator

@Lash-L Lash-L commented Dec 7, 2025

Basically, the serialization and deserialization logic was changing base64 to base_64 because of camelization and decamelization. I could modify the regex, but I was a bit worried that something might be relying on it that I'm not thinking of. I figured it would be best to make a targeted fix and revisit this once everything is stable again.

Comment on lines +35 to +38
s = s.lower()
# Temporary fix to avoid breaking any serialization.
s = s.replace("base_64", "base64")
return s
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very targetted and not ideal

Issue to track here: #644

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current set of tests should be exhaustive, so you can break anything that is not tested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regexp was modified to match the names in device features so if we just want to change field names in device features it should not be a problem to change. Agree with this change that making serialization work is more important in the short term.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will reference this in issue for tracking. Will merge for now

@Lash-L
Copy link
Collaborator Author

Lash-L commented Dec 7, 2025

This was the cause of home-assistant/core#158151 having none maps

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a serialization bug where base64 in field names was incorrectly transformed to base_64 during deserialization. The issue occurred because the _decamelize function's regex pattern splits characters before numbers (e.g., Base64Base_64), which broke field names like home_map_content_base64.

Key Changes:

  • Added a targeted string replacement in _decamelize() to convert base_64 back to base64 after decamelization
  • Added comprehensive test coverage with a new "all_fields_cache" test case that includes home_map_content_base64 field
  • Updated test snapshots to reflect the new test case across all serialization methods (default, pickle, and JSON)

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
roborock/data/containers.py Added base_64base64 replacement in _decamelize() function to fix the serialization bug
tests/devices/test_file_cache.py Added new "all_fields_cache" test case with home_map_content_base64, device_features, and trait_data to verify the fix works with end-to-end serialization
tests/devices/snapshots/test_file_cache.ambr Updated snapshots with expected outputs for the new test case across all serialization methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +75 to +78
home_map_content_base64={
1: "ZHVtbXlfbWFwX2NvbnRlbnQ=",
2: "bW9yZV9kdW1teV9jb250ZW50",
},
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this test case validates end-to-end serialization with home_map_content_base64, consider adding a direct unit test for the _decamelize and _camelize functions in tests/test_containers.py to explicitly verify the base64 edge case.

For example, add a test case to the existing test_decamelize_function parametrized test:

("homeMapContentBase64", "home_map_content_base64"),

This would make the fix more explicit and easier to maintain.

Copilot uses AI. Check for mistakes.
@Lash-L Lash-L merged commit d933ec8 into main Dec 7, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants