4
4
from homeassistant .components .select import SelectEntityDescription
5
5
from homeassistant .components .button import ButtonEntityDescription
6
6
from pymodbus .payload import BinaryPayloadBuilder , BinaryPayloadDecoder , Endian
7
- #from .const import BaseModbusSensorEntityDescription
8
7
from custom_components .solax_modbus .const import *
9
8
10
9
_LOGGER = logging .getLogger (__name__ )
42
41
DCB = 0x10000 # dry contact box - gen4
43
42
ALL_DCB_GROUP = DCB
44
43
44
+ MPPT3 = 0x40000
45
+ MPPT4 = 0x80000
46
+ MPPT6 = 0x100000
47
+ MPPT8 = 0x200000
48
+ MPPT10 = 0x400000
49
+ ALL_MPPT_GROUP = MPPT3 | MPPT4 | MPPT6 | MPPT8 | MPPT10
45
50
46
51
ALLDEFAULT = 0 # should be equivalent to HYBRID | AC | GEN2 | GEN3 | GEN4 | X1 | X3
47
52
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 ):
54
54
res = None
55
+ inverter_data = None
55
56
try :
56
57
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 ():
58
59
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" )
64
61
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 )
66
63
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 } " )
69
65
return res
70
66
71
67
@dataclass
@@ -417,14 +413,6 @@ class SolisModbusSensorEntityDescription(BaseModbusSensorEntityDescription):
417
413
418
414
@dataclass
419
415
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
- """
428
416
429
417
def determineInverterType (self , hub , configdict ):
430
418
_LOGGER .info (f"{ hub .name } : trying to determine inverter type" )
@@ -449,7 +437,6 @@ def determineInverterType(self, hub, configdict):
449
437
read_dcb = configdict .get (CONF_READ_DCB , DEFAULT_READ_DCB )
450
438
if read_eps : invertertype = invertertype | EPS
451
439
if read_dcb : invertertype = invertertype | DCB
452
- #hub.invertertype = invertertype
453
440
return invertertype
454
441
455
442
def matchInverterWithMask (self , inverterspec , entitymask , serialnumber = 'not relevant' , blacklist = None ):
@@ -459,11 +446,12 @@ def matchInverterWithMask (self, inverterspec, entitymask, serialnumber = 'not r
459
446
hybmatch = ((inverterspec & entitymask & ALL_TYPE_GROUP ) != 0 ) or (entitymask & ALL_TYPE_GROUP == 0 )
460
447
epsmatch = ((inverterspec & entitymask & ALL_EPS_GROUP ) != 0 ) or (entitymask & ALL_EPS_GROUP == 0 )
461
448
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 )
462
450
blacklisted = False
463
451
if blacklist :
464
452
for start in blacklist :
465
453
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
467
455
468
456
plugin_instance = solis_old_plugin (
469
457
plugin_name = 'Solis Old' ,
@@ -475,4 +463,4 @@ def matchInverterWithMask (self, inverterspec, entitymask, serialnumber = 'not r
475
463
block_size = 48 ,
476
464
order16 = Endian .BIG ,
477
465
order32 = Endian .BIG ,
478
- )
466
+ )
0 commit comments