Skip to content

Commit 9fbab81

Browse files
committedFeb 9, 2024·
Update Solis
1 parent 07830ae commit 9fbab81

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed
 

‎custom_components/solax_modbus/plugin_solis.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -2404,21 +2404,10 @@ def value_function_pv4_power(initval, descr, datadict):
24042404
),
24052405
]
24062406

2407-
2408-
24092407
# ============================ plugin declaration =================================================
24102408

24112409
@dataclass
24122410
class solis_plugin(plugin_base):
2413-
2414-
"""
2415-
def isAwake(self, datadict):
2416-
return (datadict.get('run_mode', None) == 'Normal Mode')
2417-
2418-
def wakeupButton(self):
2419-
return 'battery_awaken'
2420-
"""
2421-
24222411

24232412
def determineInverterType(self, hub, configdict):
24242413
_LOGGER.info(f"{hub.name}: trying to determine inverter type")
@@ -2470,7 +2459,6 @@ def matchInverterWithMask (self, inverterspec, entitymask, serialnumber = 'not r
24702459
return (genmatch and xmatch and hybmatch and epsmatch and dcbmatch and mpptmatch) and not blacklisted
24712460

24722461

2473-
24742462
plugin_instance = solis_plugin(
24752463
plugin_name = 'Solis',
24762464
plugin_manufacturer = 'Ginlog Solis',
@@ -2482,4 +2470,4 @@ def matchInverterWithMask (self, inverterspec, entitymask, serialnumber = 'not r
24822470
order16 = Endian.BIG,
24832471
order32 = Endian.BIG,
24842472
auto_block_ignore_readerror = True
2485-
)
2473+
)

‎custom_components/solax_modbus/plugin_solis_old.py

+15-27
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from homeassistant.components.select import SelectEntityDescription
55
from homeassistant.components.button import ButtonEntityDescription
66
from pymodbus.payload import BinaryPayloadBuilder, BinaryPayloadDecoder, Endian
7-
#from .const import BaseModbusSensorEntityDescription
87
from custom_components.solax_modbus.const import *
98

109
_LOGGER = logging.getLogger(__name__)
@@ -42,30 +41,27 @@
4241
DCB = 0x10000 # dry contact box - gen4
4342
ALL_DCB_GROUP = DCB
4443

44+
MPPT3 = 0x40000
45+
MPPT4 = 0x80000
46+
MPPT6 = 0x100000
47+
MPPT8 = 0x200000
48+
MPPT10 = 0x400000
49+
ALL_MPPT_GROUP = MPPT3 | MPPT4 | MPPT6 | MPPT8 | MPPT10
4550

4651
ALLDEFAULT = 0 # should be equivalent to HYBRID | AC | GEN2 | GEN3 | GEN4 | X1 | X3
4752

48-
49-
# ======================= end of bitmask handling code =============================================
50-
51-
# ====================== find inverter type and details ===========================================
52-
53-
def _read_serialnr(hub, address, swapbytes):
53+
def _read_serialnr(hub, address):
5454
res = None
55+
inverter_data = None
5556
try:
5657
inverter_data = hub.read_input_registers(unit=hub._modbus_addr, address=address, count=4)
57-
if not inverter_data.isError():
58+
if not inverter_data.isError():
5859
decoder = BinaryPayloadDecoder.fromRegisters(inverter_data.registers, byteorder=Endian.BIG)
59-
res = decoder.decode_string(8).decode
60-
if swapbytes:
61-
ba = bytearray(res) # convert to bytearray for swapping
62-
ba[0::2], ba[1::2] = ba[1::2], ba[0::2] # swap bytes ourselves - due to bug in Endian.LITTLE ?
63-
res = str(ba) # convert back to string
60+
res = decoder.decode_string(8).decode("ascii")
6461
hub.seriesnumber = res
65-
except Exception as ex: _LOGGER.warning(f"{hub.name}: attempt to read serialnumber failed at 0x{address:x}", exc_info=True)
62+
except Exception as ex: _LOGGER.warning(f"{hub.name}: attempt to read serialnumber failed at 0x{address:x} data: {inverter_data}", exc_info=True)
6663
if not res: _LOGGER.warning(f"{hub.name}: reading serial number from address 0x{address:x} failed; other address may succeed")
67-
_LOGGER.info(f"Read {hub.name} 0x{address:x} serial number: {res}, swapped: {swapbytes}")
68-
#return 'SP1ES2'
64+
_LOGGER.info(f"Read {hub.name} 0x{address:x} serial number before potential swap: {res}")
6965
return res
7066

7167
@dataclass
@@ -417,14 +413,6 @@ class SolisModbusSensorEntityDescription(BaseModbusSensorEntityDescription):
417413

418414
@dataclass
419415
class solis_old_plugin(plugin_base):
420-
421-
"""
422-
def isAwake(self, datadict):
423-
return (datadict.get('run_mode', None) == 'Normal Mode')
424-
425-
def wakeupButton(self):
426-
return 'battery_awaken'
427-
"""
428416

429417
def determineInverterType(self, hub, configdict):
430418
_LOGGER.info(f"{hub.name}: trying to determine inverter type")
@@ -449,7 +437,6 @@ def determineInverterType(self, hub, configdict):
449437
read_dcb = configdict.get(CONF_READ_DCB, DEFAULT_READ_DCB)
450438
if read_eps: invertertype = invertertype | EPS
451439
if read_dcb: invertertype = invertertype | DCB
452-
#hub.invertertype = invertertype
453440
return invertertype
454441

455442
def matchInverterWithMask (self, inverterspec, entitymask, serialnumber = 'not relevant', blacklist = None):
@@ -459,11 +446,12 @@ def matchInverterWithMask (self, inverterspec, entitymask, serialnumber = 'not r
459446
hybmatch = ((inverterspec & entitymask & ALL_TYPE_GROUP) != 0) or (entitymask & ALL_TYPE_GROUP == 0)
460447
epsmatch = ((inverterspec & entitymask & ALL_EPS_GROUP) != 0) or (entitymask & ALL_EPS_GROUP == 0)
461448
dcbmatch = ((inverterspec & entitymask & ALL_DCB_GROUP) != 0) or (entitymask & ALL_DCB_GROUP == 0)
449+
mpptmatch = ((inverterspec & entitymask & ALL_MPPT_GROUP) != 0) or (entitymask & ALL_MPPT_GROUP == 0)
462450
blacklisted = False
463451
if blacklist:
464452
for start in blacklist:
465453
if serialnumber.startswith(start) : blacklisted = True
466-
return (genmatch and xmatch and hybmatch and epsmatch and dcbmatch) and not blacklisted
454+
return (genmatch and xmatch and hybmatch and epsmatch and dcbmatch and mpptmatch) and not blacklisted
467455

468456
plugin_instance = solis_old_plugin(
469457
plugin_name = 'Solis Old',
@@ -475,4 +463,4 @@ def matchInverterWithMask (self, inverterspec, entitymask, serialnumber = 'not r
475463
block_size = 48,
476464
order16 = Endian.BIG,
477465
order32 = Endian.BIG,
478-
)
466+
)

0 commit comments

Comments
 (0)