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 e13e733
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,9 @@

default:
update_interval: 60
code: 0x04
digits: 6

requests:
- start: 0x0000
end: 0x001A
mb_functioncode: 0x04

- start: 0x0000
end: 0x000F
mb_functioncode: 0x03

parameters:
- group: solar
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

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

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

parameters:
- group: solar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,16 @@

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

requests:
# Inverter State
- start: 0x0200
end: 0x0245
mb_functioncode: 0x03
# Inverter Settings
- start: 0x10B0
end: 0x10BC
mb_functioncode: 0x04
# Inverter Information
code: 0x04
- start: 0x2000
end: 0x200B
mb_functioncode: 0x04
code: 0x04

parameters:
- group: Generation
Expand Down
12 changes: 2 additions & 10 deletions custom_components/solarman/inverter_definitions/solis_hybrid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,13 @@

default:
update_interval: 10
code: 0x04
digits: 6

requests:
- start: 33029
end: 33095
mb_functioncode: 0x04
- start: 33116
end: 33179
mb_functioncode: 0x04
- start: 33206
end: 33282
mb_functioncode: 0x04
- start: 43000
end: 43150
mb_functioncode: 0x03
code: 0x03

parameters:
- group: InverterStatus
Expand Down
16 changes: 12 additions & 4 deletions custom_components/solarman/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ 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]:
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 +93,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 e13e733

Please sign in to comment.