diff --git a/custom_components/solarman/inverter_definitions/afore_BNTxxxKTL-2mppt.yaml b/custom_components/solarman/inverter_definitions/afore_BNTxxxKTL-2mppt.yaml index b0bebebd..a8a850df 100644 --- a/custom_components/solarman/inverter_definitions/afore_BNTxxxKTL-2mppt.yaml +++ b/custom_components/solarman/inverter_definitions/afore_BNTxxxKTL-2mppt.yaml @@ -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: diff --git a/custom_components/solarman/inverter_definitions/sofar_hyd3k-6k-es.yaml b/custom_components/solarman/inverter_definitions/sofar_hyd3k-6k-es.yaml index 09541e3b..9bfba5c9 100644 --- a/custom_components/solarman/inverter_definitions/sofar_hyd3k-6k-es.yaml +++ b/custom_components/solarman/inverter_definitions/sofar_hyd3k-6k-es.yaml @@ -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 diff --git a/custom_components/solarman/inverter_definitions/sofar_wifikit.yaml b/custom_components/solarman/inverter_definitions/sofar_wifikit.yaml index c6934599..964553c0 100644 --- a/custom_components/solarman/inverter_definitions/sofar_wifikit.yaml +++ b/custom_components/solarman/inverter_definitions/sofar_wifikit.yaml @@ -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 diff --git a/custom_components/solarman/inverter_definitions/solis_hybrid.yaml b/custom_components/solarman/inverter_definitions/solis_hybrid.yaml index 75f82ea9..23f16353 100644 --- a/custom_components/solarman/inverter_definitions/solis_hybrid.yaml +++ b/custom_components/solarman/inverter_definitions/solis_hybrid.yaml @@ -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 diff --git a/custom_components/solarman/parser.py b/custom_components/solarman/parser.py index ec773a3f..2981bfd4 100644 --- a/custom_components/solarman/parser.py +++ b/custom_components/solarman/parser.py @@ -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 = [] @@ -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():