diff --git a/custom_components/solarman/common.py b/custom_components/solarman/common.py index 3a1b444..401860d 100644 --- a/custom_components/solarman/common.py +++ b/custom_components/solarman/common.py @@ -29,10 +29,10 @@ async def yaml_open(file): def all_same(values): return all(i == values[0] for i in values) -def group_when(iterable, predicate): +def group_when(iterable, predicate, max_size = REQUEST_MAX_SIZE): i, x, size = 0, 0, len(iterable) while i < size - 1: - if predicate(iterable[i], iterable[i + 1]): + if predicate(iterable[i], iterable[i + 1]) or iterable[i + 1] - iterable[x] > max_size: yield iterable[x:i + 1] x = i + 1 i += 1 diff --git a/custom_components/solarman/const.py b/custom_components/solarman/const.py index 027047c..3304190 100644 --- a/custom_components/solarman/const.py +++ b/custom_components/solarman/const.py @@ -57,6 +57,7 @@ ATTR_FRIENDLY_NAME = "friendly_name" REQUEST_UPDATE_INTERVAL = "update_interval" +REQUEST_MAX_SIZE = 125 REQUEST_MIN_SPAN = "min_span" REQUEST_CODE = "code" REQUEST_CODE_ALT = "mb_functioncode"