Skip to content

Commit

Permalink
feat: Added Program X SOC configuration items
Browse files Browse the repository at this point in the history
feat: Multiple attempts when trying to write into registers
  • Loading branch information
davidrapan committed Jul 18, 2024
1 parent 99f2dc3 commit 009e08a
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 37 deletions.
56 changes: 36 additions & 20 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,42 @@ async def async_get(self, runtime = 0):

async def service_write_holding_register(self, register, value) -> bool:
_LOGGER.debug(f"service_write_holding_register: {register}, value: {value}")
try:
await self.async_connect()
response = await self.write_holding_register(register, value)
_LOGGER.debug(f"service_write_holding_register: {register}, response: {response}")
except Exception as e:
_LOGGER.warning(f"service_write_holding_register: {register}, value: {value} failed. [{format_exception(e)}]")
if not self.auto_reconnect:
await self.async_disconnect()
raise
return True

attempts_left = ACTION_RETRY_ATTEMPTS
while attempts_left > 0:
attempts_left -= 1

try:
await self.async_connect()
response = await self.write_holding_register(register, value)
_LOGGER.debug(f"service_write_holding_register: {register}, response: {response}")
return True
except Exception as e:
_LOGGER.warning(f"service_write_holding_register: {register}, value: {value} failed, attempts left: {attempts_left}. [{format_exception(e)}]")
if not self.auto_reconnect:
await self.async_disconnect()
if not attempts_left > 0:
raise

await asyncio.sleep(TIMINGS_WRITE_EXCEPT_SLEEP)

async def service_write_multiple_holding_registers(self, register, values) -> bool:
_LOGGER.debug(f"service_write_multiple_holding_registers: {register}, values: {values}")
try:
await self.async_connect()
response = await self.write_multiple_holding_registers(register, values)
_LOGGER.debug(f"service_write_multiple_holding_register: {register}, response: {response}")
except Exception as e:
_LOGGER.warning(f"service_write_multiple_holding_registers: {register}, values: {values} failed. [{format_exception(e)}]")
if not self.auto_reconnect:
await self.async_disconnect()
raise
return True

attempts_left = ACTION_RETRY_ATTEMPTS
while attempts_left > 0:
attempts_left -= 1

try:
await self.async_connect()
response = await self.write_multiple_holding_registers(register, values)
_LOGGER.debug(f"service_write_multiple_holding_register: {register}, response: {response}")
return True
except Exception as e:
_LOGGER.warning(f"service_write_multiple_holding_registers: {register}, values: {values} failed, attempts left: {attempts_left}. [{format_exception(e)}]")
if not self.auto_reconnect:
await self.async_disconnect()
if not attempts_left > 0:
raise

await asyncio.sleep(TIMINGS_WRITE_EXCEPT_SLEEP)
3 changes: 2 additions & 1 deletion custom_components/solarman/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
TIMINGS_INTERVAL = 5
TIMINGS_UPDATE_INTERVAL = td(seconds = TIMINGS_INTERVAL)
TIMINGS_UPDATE_TIMEOUT = TIMINGS_INTERVAL * 6
TIMINGS_SOCKET_TIMEOUT = TIMINGS_INTERVAL * 3 - 1
TIMINGS_SOCKET_TIMEOUT = TIMINGS_INTERVAL * 3
TIMINGS_QUERY_INTERVAL_DEFAULT = 60
TIMINGS_QUERY_EXCEPT_SLEEP = 3
TIMINGS_WRITE_EXCEPT_SLEEP = 1

REGISTERS_MIN_SPAN_DEFAULT = 25
REGISTERS_DIGITS_DEFAULT = 6
Expand Down
91 changes: 87 additions & 4 deletions custom_components/solarman/inverter_definitions/deye_sg01hp3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,101 @@ parameters:
- key: "default"
value: "On"

- group: Solar Sell
- group: Work Mode
items:
- name: "Solar Sell"
- name: Export Surplus
update_interval: 30
class: ""
class: "switch"
state_class: ""
uom: ""
scale: 1
rule: 1
switch: True
registers: [0x0091]

- name: Program 1 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A6]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 2 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A7]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 3 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A8]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 4 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A9]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 5 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00AA]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 6 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00AB]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- group: BMS
items:
- name: "BMS Charging Voltage"
Expand Down
91 changes: 87 additions & 4 deletions custom_components/solarman/inverter_definitions/deye_sg04lp3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,101 @@ parameters:
- key: "default"
value: "On"

- group: Solar Sell
- group: Work Mode
items:
- name: "Solar Sell"
- name: Export Surplus
update_interval: 30
class: ""
class: "switch"
state_class: ""
uom: ""
scale: 1
rule: 1
switch: True
registers: [0x0091]

- name: Program 1 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A6]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 2 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A7]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 3 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A8]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 4 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A9]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 5 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00AA]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 6 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00AB]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- group: BMS
items:
- name: "BMS Charged Voltage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ parameters:
- key: "default"
value: "On"

- group: Solar Sell
- group: Work Mode
items:
- name: "Solar Sell"
- name: Export Surplus
update_interval: 30
class: "switch"
state_class: ""
Expand All @@ -406,6 +406,90 @@ parameters:
rule: 1
registers: [0x0091]

- name: Program 1 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A6]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 2 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A7]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 3 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A8]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 4 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00A9]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 5 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00AA]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- name: Program 6 SOC
update_interval: 30
class: ""
state_class: measurement
uom: "%"
scale: 1
rule: 1
registers: [0x00AB]
configurable:
range:
min: 0
max: 100
icon: mdi:sun-clock

- group: BMS
items:
- name: "BMS Charged Voltage"
Expand Down
Loading

0 comments on commit 009e08a

Please sign in to comment.