Skip to content

Commit

Permalink
refactor: Inverter.get - requests through ensure_list
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Dec 10, 2024
1 parent 9ea5c56 commit 9ab2597
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async def try_read_write(self, code, start, arg, message, incremental_wait):
return response

async def get(self, runtime = 0, requests = None):
scheduled, scheduled_count = safe_list_len(self.profile.parser.schedule_requests(runtime) if not requests else requests)
scheduled, scheduled_count = ensure_list_safe_len(self.profile.parser.schedule_requests(runtime) if not requests else requests)
responses, result = {}, {}

_LOGGER.debug(f"[{self.config.serial}] Scheduling {scheduled_count} query request{'' if scheduled_count == 1 else 's'}. ^{runtime}")
Expand Down
4 changes: 2 additions & 2 deletions custom_components/solarman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def bulk_safe_delete(target: dict[Any, Any], redirect: dict):
def ensure_list(value):
return value if isinstance(value, list) else [value]

def safe_list_len(value: list):
return value, len(value) if value is not None and isinstance(value, list) else 0
def ensure_list_safe_len(value: list):
return ensure_list(value), len(value) if value is not None and isinstance(value, list) else 0

def set_request(code, start, end):
return { REQUEST_CODE: code, REQUEST_START: start, REQUEST_END: end }
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solarman/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def attributes(self) -> str:
async def resolve(self, request: Callable[[], Awaitable[None]] | None = None):
_LOGGER.debug(f"Device autodetection is {"enabled" if self.auto and request else f"disabled. Selected profile: {self.filename}"}")

f = lookup_profile(await request(-1, [set_request(*AUTODETECTION_REQUEST_DEYE)]), self.attributes) if self.auto and request else self.filename
f = lookup_profile(await request(-1, set_request(*AUTODETECTION_REQUEST_DEYE)), self.attributes) if self.auto and request else self.filename

if f and f != DEFAULT_[CONF_LOOKUP_FILE] and (n := process_profile(f)) and (p := await yaml_open(self.config.directory + n)):
self.parser = ParameterParser(p, self.attributes)
Expand Down

0 comments on commit 9ab2597

Please sign in to comment.