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

Order of supportedProtocols is not preserved #424

Open
js-tud opened this issue Jul 3, 2024 · 0 comments
Open

Order of supportedProtocols is not preserved #424

js-tud opened this issue Jul 3, 2024 · 0 comments

Comments

@js-tud
Copy link

js-tud commented Jul 3, 2024

Hello,

if I enter multiple protocols in the evcc_config file, the order is not preserved due to the use of set() in functions _format_list() and load_requested_protocols() located in iso15118/shared/utils.py

This is a quick fix that preserves the priority order found in https://stackoverflow.com/a/58666031 and https://stackoverflow.com/a/23529016

"""removes duplicates and preserves order"""
def _ordered_list_without_duplicates(l: List[str]) -> List[str]:
    tmp = set()
    return [x for x in l if not (x in tmp or tmp.add(x))]

"""intersects two lists and preserves order of list1"""
def _ordered_intersected_lists(list1: List[str], list2: List[str]) -> List[str]:
    set2 = set(list2)
    return [x for x in list1 if x in set2]

def _format_list(read_settings: List[str]) -> List[str]:
    read_settings = list(filter(None, read_settings))
    read_settings = [setting.strip().upper() for setting in read_settings]
#    read_settings = list(set(read_settings))
    return _ordered_list_without_duplicates(read_settings)

def load_requested_protocols(read_protocols: Optional[List[str]]) -> List[Protocol]:
    supported_protocols = [
        "ISO_15118_2",
        "ISO_15118_20_AC",
        "ISO_15118_20_DC",
        "DIN_SPEC_70121",
    ]
    protocols = _format_list(read_protocols)
#    valid_protocols = list(set(protocols).intersection(supported_protocols))
    valid_protocols = _ordered_intersected_lists(protocols, supported_protocols)

    if not valid_protocols:
        raise NoSupportedProtocols(
            f"No supported protocols configured. Supported protocols are "
            f"{supported_protocols} and could be configured in evcc_config.json"
        )
    return [Protocol[name] for name in valid_protocols if name in Protocol.__members__]
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

No branches or pull requests

1 participant