Skip to content

Commit

Permalink
refactor: Number of Battery packs - be able to disable reading when s…
Browse files Browse the repository at this point in the history
…et to 0
  • Loading branch information
davidrapan committed Feb 12, 2025
1 parent 4524419 commit 3b28082
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion custom_components/solarman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def lookup_profile(request, attr):
if (v := get_addr_value(response, AUTODETECTION_CODE_DEYE, c)) and (t := (v & 0x0F00) // 0x100) and (p := v & 0x000F) and (t := 2 if t > 12 else t) and (p := 3 if p > 3 else p):
attr[ATTR_[CONF_MOD]], attr[ATTR_[CONF_MPPT]], attr[ATTR_[CONF_PHASE]] = max(m, attr[ATTR_[CONF_MOD]]), min(t, attr[ATTR_[CONF_MPPT]]), min(p, attr[ATTR_[CONF_PHASE]])
if device_type in (0x0005, 0x0500, 0x0006, 0x0007, 0x0600, 0x0008, 0x0601) and (response := await request(-1, set_request(0x0003, 0x2712, 0x2712))) and (p := get_addr_value(response, 0x0003, 0x2712)) is not None:
attr[ATTR_[CONF_PACK]] = max(p, attr[ATTR_[CONF_PACK]])
attr[ATTR_[CONF_PACK]] = p if attr[ATTR_[CONF_PACK]] == DEFAULT_[CONF_PACK] else min(p, attr[ATTR_[CONF_PACK]])
return f
raise Exception("Unable to read Device Type at address 0x0000")

Expand Down
2 changes: 1 addition & 1 deletion custom_components/solarman/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
vol.Optional(CONF_MOD, default = DEFAULT_[CONF_MOD], description = {SUGGESTED_VALUE: DEFAULT_[CONF_MOD]}): bool,
vol.Optional(CONF_MPPT, default = DEFAULT_[CONF_MPPT], description = {SUGGESTED_VALUE: DEFAULT_[CONF_MPPT]}): vol.All(vol.Coerce(int), vol.Range(min = 1, max = 12)),
vol.Optional(CONF_PHASE, default = DEFAULT_[CONF_PHASE], description = {SUGGESTED_VALUE: DEFAULT_[CONF_PHASE]}): vol.All(vol.Coerce(int), vol.Range(min = 1, max = 3)),
vol.Optional(CONF_PACK, default = DEFAULT_[CONF_PACK], description = {SUGGESTED_VALUE: DEFAULT_[CONF_PACK]}): vol.All(vol.Coerce(int), vol.Range(min = 0, max = 8)),
vol.Optional(CONF_PACK, default = DEFAULT_[CONF_PACK], description = {SUGGESTED_VALUE: DEFAULT_[CONF_PACK]}): vol.All(vol.Coerce(int), vol.Range(min = -1, max = 8)),
vol.Optional(CONF_BATTERY_NOMINAL_VOLTAGE, default = DEFAULT_[CONF_BATTERY_NOMINAL_VOLTAGE], description = {SUGGESTED_VALUE: DEFAULT_[CONF_BATTERY_NOMINAL_VOLTAGE]}): cv.positive_int,
vol.Optional(CONF_BATTERY_LIFE_CYCLE_RATING, default = DEFAULT_[CONF_BATTERY_LIFE_CYCLE_RATING], description = {SUGGESTED_VALUE: DEFAULT_[CONF_BATTERY_LIFE_CYCLE_RATING]}): cv.positive_int,
vol.Optional(CONF_MB_SLAVE_ID, default = DEFAULT_[CONF_MB_SLAVE_ID], description = {SUGGESTED_VALUE: DEFAULT_[CONF_MB_SLAVE_ID]}): cv.positive_int
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solarman/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
CONF_MOD: False,
CONF_MPPT: 4,
CONF_PHASE: 3,
CONF_PACK: 0,
CONF_PACK: -1,
CONF_BATTERY_NOMINAL_VOLTAGE: 48,
CONF_BATTERY_LIFE_CYCLE_RATING: 6000,
UPDATE_INTERVAL: 60,
Expand Down

0 comments on commit 3b28082

Please sign in to comment.