Skip to content

Commit

Permalink
improve namespace key euristics
Browse files Browse the repository at this point in the history
  • Loading branch information
krahabb committed Jan 24, 2024
1 parent 0a59cf6 commit 6f70107
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions custom_components/meross_lan/merossclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,14 @@ def __getitem__(self, namespace: str) -> str:
key = next(iter(mc.PAYLOAD_GET[namespace]))
else:
key = namespace.split(".")[-1]
key = key[0].lower() + key[1:]
# mainly camelCasing the last split of the namespace
# with special care for also the last char which looks
# lowercase when it's a X (i.e. ToggleX -> togglex)
lastchar = key[-1]
if lastchar == "X":
key = "".join((key[0].lower(), key[1:-1], "x"))
else:
key = "".join((key[0].lower(), key[1:]))

NAMESPACE_TO_KEY[namespace] = key
KEY_TO_NAMESPACE[key] = namespace
Expand Down Expand Up @@ -296,17 +303,14 @@ def get_default_payload(namespace: str) -> MerossPayloadType:
"""
if namespace in mc.PAYLOAD_GET:
return mc.PAYLOAD_GET[namespace]
split = namespace.split(".")
key = split[-1]
key = key[0].lower() + key[1:]
match split:
match namespace.split("."):
case (_, "Hub", *args):
return {key: []}
return {NAMESPACE_TO_KEY[namespace]: []}
case (_, "RollerShutter", *args):
return {key: []}
return {NAMESPACE_TO_KEY[namespace]: []}
case (_, _, "Thermostat", *args):
return {key: [{mc.KEY_CHANNEL: 0}]}
return {key: {}}
return {NAMESPACE_TO_KEY[namespace]: [{mc.KEY_CHANNEL: 0}]}
return {NAMESPACE_TO_KEY[namespace]: {}}


def get_default_arguments(namespace: str):
Expand Down

0 comments on commit 6f70107

Please sign in to comment.