Skip to content

Commit

Permalink
feat: Request sets now used for mb code selection
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Aug 10, 2024
1 parent b43b74c commit 0ecb2f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

default:
update_interval: 5
code: 0x03
digits: 6

requests:
- start: 0x0200
end: 0x0255
mb_functioncode: 0x03
code: 0x03
- start: 0x10B0
end: 0x10BC
mb_functioncode: 0x04
code: 0x04

parameters:
- group: solar
Expand Down
17 changes: 13 additions & 4 deletions custom_components/solarman/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,18 @@ def get_sensors(self):

return result

def get_requests(self, runtime = 0):
def get_request_code(self, start, end):
if "requests" in self._profile:
_LOGGER.debug("Dynamic requests and many more features are disabled cause of an old profile format!")
for r in self._profile["requests"]:
if r[REQUEST_START] <= start <= end <= r[REQUEST_END]:
_LOGGER.debug(f"CODE: {get_request_code(r)}")
return get_request_code(r)

return self._code

def get_requests(self, runtime = 0):
if "requests" in self._profile and "requests_fine_control" in self._profile:
_LOGGER.debug("Fine control of request sets is enabled!")
return self._profile["requests"]

registers = []
Expand All @@ -85,8 +94,8 @@ def get_requests(self, runtime = 0):
registers.sort()

groups = group_when(registers, lambda x, y: y - x > self._min_span)
return [{ REQUEST_START: r[0], REQUEST_END: r[-1], REQUEST_CODE: self._code } for r in groups]

return [{ REQUEST_START: r[0], REQUEST_END: r[-1], REQUEST_CODE: self.get_request_code(r[0], r[-1]) } for r in groups]

def parse(self, rawData, start, length):
for param in self.parameters():
Expand Down

0 comments on commit 0ecb2f2

Please sign in to comment.