Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Settings conditional dict #1777

Merged
merged 54 commits into from
Jul 8, 2021
Merged

Conversation

iLLiCiTiT
Copy link
Member

@iLLiCiTiT iLLiCiTiT commented Jun 29, 2021

Description

Implementing concept of one entity value modifying children entities of dictionary. Added dict-conditional entity type which always have one entity with enumerator where value of enumerator change other children of dictionary.

Changes

  • added the dict-conditional entity type for settings
  • parent can tell if missing defaults can be skipped or not

Example schema of dict-conditional

{
    "type": "dict-conditional",
    "key": "my_key",
    "label": "My Key",
    "enum_key": "type",
    "enum_label": "label",
    "enum_children": [
        # Each item must be a dictionary with 'key'
        {
            "key": "action",
            "label": "Action",
            "children": [
                {
                    "type": "text",
                    "key": "key",
                    "label": "Key"
                },
                {
                    "type": "text",
                    "key": "label",
                    "label": "Label"
                },
                {
                    "type": "text",
                    "key": "command",
                    "label": "Comand"
                }
            ]
        },
        {
            "key": "menu",
            "label": "Menu",
            "children": [
                {
                    "key": "children",
                    "label": "Children",
                    "type": "list",
                    "object_type": "text"
                }
            ]
        },
        {
            # Separator does not have children as "separator" value is enough
            "key": "separator",
            "label": "Separator"
        }
    ]
}

Example output of example schema

# When enum is set to "separator"
{
    "type": "separator"
}

# When enum is set to "action"
{
    "type": "action",
    "key": "action_1",
    "label": "Action 1",
    "command": "run command -arg"
}

# When enum is set to "menu"
{
    "type": "menu",
    "children": [
        "child_1",
        "child_2"
    ]
}

How to test

Currently not used in schemas but example is available in example_schema.json.

  • SyncServer must be modified to be able use this ability
    • must have ability to return schemas for each provider without loading settings itself (endless loop of error)
  • if list will have ability to define it's object type using templates it would be possible to use conditional dict for scripts menu (similar to example but menu would have list with whole schema as children).

Depends on: #1753

@@ -320,22 +322,30 @@ def _get_metadata_for_state(self, state):
def _metadata_for_current_state(self):
return self._get_metadata_for_state(self._override_state)

def set_override_state(self, state):
def set_override_state(self, state, ignore_missing_defaults):
Copy link

Choose a reason for hiding this comment

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

'DictMutableKeysEntity.set_override_state' is too complex (32)

@iLLiCiTiT iLLiCiTiT marked this pull request as ready for review July 7, 2021 17:44
@iLLiCiTiT iLLiCiTiT self-assigned this Jul 7, 2021
@iLLiCiTiT iLLiCiTiT added backend type: enhancement Enhancements to existing functionality labels Jul 7, 2021
@64qam
Copy link
Member

64qam commented Jul 8, 2021

For Menu item...
image

@iLLiCiTiT
Copy link
Member Author

For Menu item...

Should be fixed now.

@iLLiCiTiT iLLiCiTiT merged commit e617873 into develop Jul 8, 2021
@mkolar mkolar deleted the feature/settings_conditional_dict branch August 10, 2021 16:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement Enhancements to existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants