Skip to content

Commit

Permalink
lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerza committed Oct 14, 2024
1 parent b645daf commit e7c3444
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ha_addon_sunsynk_multi/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def unmarshal(target: object, json_data: dict) -> object:
_LOGGER.error("Invalid options format: %s", json_data)
return target

_lst = getattr(target, "_LISTS", {})
_lst = getattr(target, "_lists", {})

for key, val in json_data.items():
key = fixkey(key)

if key in _lst: # Handle lists (e.g., inverters, schedules)
newcls = _lst[key]
if isinstance(val, list):
Expand All @@ -36,15 +36,15 @@ def unmarshal(target: object, json_data: dict) -> object:
newv = [unmarshal(newcls(), item) for item in val]
setattr(target, key, newv)
continue

# Handle simple type conversion if necessary
target_old = getattr(target, key)
setattr(target, key, val)
for thetype in [int, str]:
if isinstance(target_old, thetype):
setattr(target, key, thetype(val))
break

return target


Expand All @@ -63,7 +63,7 @@ class InverterOptions:
class Options:
"""HASS Addon Options."""

_LISTS = {"inverters": InverterOptions, "schedules": Schedule}
_lists = {"inverters": InverterOptions, "schedules": Schedule}

mqtt_host: str = os.getenv("MQTT_HOST", "")
mqtt_port: int = int(os.getenv("MQTT_PORT", "0"))
Expand Down

0 comments on commit e7c3444

Please sign in to comment.