Skip to content

Commit

Permalink
fix: Number platform - missing offset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Sep 26, 2024
1 parent 72c0639 commit c0a3636
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 9 deletions.
45 changes: 41 additions & 4 deletions custom_components/solarman/inverter_definitions/deye_2mppt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ parameters:

- group: Settings
items:
- name: "Start-up Self-checking Time"
- name: "Self-check time"
platform: number
uom: "s"
rule: 1
Expand Down Expand Up @@ -388,6 +388,7 @@ parameters:
configurable:
min: 45
max: 65
step: 0.01
range:
min: 4500
max: 6500
Expand All @@ -403,11 +404,42 @@ parameters:
configurable:
min: 45
max: 65
step: 0.01
range:
min: 4500
max: 6500

- name: "Over-Frequency Load Reduction Starting Point"
- name: "Starting Voltage Upper Limit"
platform: number
class: "voltage"
state_class: "measurement"
uom: "V"
scale: 0.1
rule: 1
registers: [0x0020]
configurable:
min: 700
max: 900
range:
min: 7000
max: 9000

- name: "Starting Voltage Lower Limit"
platform: number
class: "voltage"
state_class: "measurement"
uom: "V"
scale: 0.1
rule: 1
registers: [0x0021]
configurable:
min: 700
max: 900
range:
min: 7000
max: 9000

- name: "Over-Frequency Load Reduction Start"
platform: number
class: "frequency"
state_class: "measurement"
Expand All @@ -418,11 +450,12 @@ parameters:
configurable:
min: 45
max: 65
step: 0.01
range:
min: 4500
max: 6500

- name: "Over-Frequency Load Reduction Percentage"
- name: "Over-Frequency Load Reduction"
platform: number
state_class: "measurement"
uom: "%"
Expand All @@ -439,6 +472,10 @@ parameters:
offset: 1000
rule: 1
registers: [0x0027]
configurable:
min: -1
max: 1
step: 0.001
range:
min: 0
max: 2000
Expand Down Expand Up @@ -496,7 +533,7 @@ parameters:
registers: [0x0036]
lookup:
- key: 0
value: "Normal operation"
value: "Normal"
- key: 1
value: "Initialize the control board EEPROM"
- key: 2
Expand Down
45 changes: 41 additions & 4 deletions custom_components/solarman/inverter_definitions/deye_4mppt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ parameters:

- group: Settings
items:
- name: "Start-up Self-checking Time"
- name: "Self-check time"
platform: number
uom: "s"
rule: 1
Expand Down Expand Up @@ -507,6 +507,7 @@ parameters:
configurable:
min: 45
max: 65
step: 0.01
range:
min: 4500
max: 6500
Expand All @@ -522,11 +523,42 @@ parameters:
configurable:
min: 45
max: 65
step: 0.01
range:
min: 4500
max: 6500

- name: "Over-Frequency Load Reduction Starting Point"
- name: "Starting Voltage Upper Limit"
platform: number
class: "voltage"
state_class: "measurement"
uom: "V"
scale: 0.1
rule: 1
registers: [0x0020]
configurable:
min: 700
max: 900
range:
min: 7000
max: 9000

- name: "Starting Voltage Lower Limit"
platform: number
class: "voltage"
state_class: "measurement"
uom: "V"
scale: 0.1
rule: 1
registers: [0x0021]
configurable:
min: 700
max: 900
range:
min: 7000
max: 9000

- name: "Over-Frequency Load Reduction Start"
platform: number
class: "frequency"
state_class: "measurement"
Expand All @@ -537,11 +569,12 @@ parameters:
configurable:
min: 45
max: 65
step: 0.01
range:
min: 4500
max: 6500

- name: "Over-Frequency Load Reduction Percentage"
- name: "Over-Frequency Load Reduction"
platform: number
state_class: "measurement"
uom: "%"
Expand All @@ -558,6 +591,10 @@ parameters:
offset: 1000
rule: 1
registers: [0x0027]
configurable:
min: -1
max: 1
step: 0.001
range:
min: 0
max: 2000
Expand Down Expand Up @@ -615,7 +652,7 @@ parameters:
registers: [0x0036]
lookup:
- key: 0
value: "Normal operation"
value: "Normal"
- key: 1
value: "Initialize the control board EEPROM"
- key: 2
Expand Down
12 changes: 11 additions & 1 deletion custom_components/solarman/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,17 @@ def __init__(self, coordinator, sensor):
SolarmanEntity.__init__(self, coordinator, _PLATFORM, sensor)
self._attr_entity_category = EntityCategory.CONFIG

if "mode" in sensor and (mode := sensor["mode"]):
self._attr_mode = mode

self.scale = None
if "scale" in sensor:
self.scale = get_number(sensor["scale"])

self.offset = None
if "offset" in sensor:
self.offset = get_number(sensor["offset"])

registers = sensor["registers"]
registers_length = len(registers)
if registers_length > 0:
Expand All @@ -69,7 +76,10 @@ def __init__(self, coordinator, sensor):

async def async_set_native_value(self, value: float) -> None:
"""Update the setting."""
if await self.coordinator.inverter.call(CODE.WRITE_MULTIPLE_HOLDING_REGISTERS, self.register, [int(value if self.scale is None else value / self.scale),], ACTION_ATTEMPTS_MAX) > 0:
value_int = int(value if self.scale is None else value / self.scale)
if self.offset is not None:
value_int += self.offset
if await self.coordinator.inverter.call(CODE.WRITE_MULTIPLE_HOLDING_REGISTERS, self.register, [value_int,], ACTION_ATTEMPTS_MAX) > 0:
self.set_state(get_number(value))
self.async_write_ha_state()
#await self.entity_description.update_fn(self.coordinator., int(value))
Expand Down

0 comments on commit c0a3636

Please sign in to comment.