@@ -558,7 +558,54 @@ class OpenAPI {
558558 , type : 'number'
559559 , unit : 'kWh'
560560 } ]
561+ } ,
562+ {
563+ Group : 'Wallbox'
564+ , fnct : this . getWallboxData . bind ( this )
565+ , enabledName : 'oAEnableWallbox'
566+ , intervalName : 'oAIntervalWallboxMins'
567+ , intervalFactor : 60
568+ , states : [
569+ {
570+ alphaAttrName : 'evchargerSn'
571+ , role : 'value'
572+ , id : 'SN'
573+ , name : 'Wallbox serial number'
574+ , type : 'string'
575+ , unit : ''
576+ , isStatic : true
577+ } ,
578+ {
579+ alphaAttrName : 'evchargerModel'
580+ , role : 'value'
581+ , id : 'Model'
582+ , name : 'Wallbox model'
583+ , type : 'string'
584+ , unit : ''
585+ , isStatic : true
586+ } ,
587+ {
588+ alphaAttrName : 'evchargerStatus'
589+ , role : 'value'
590+ , id : 'Status'
591+ , name : 'Wallbox status'
592+ , type : 'number'
593+ , unit : ''
594+ , states : {
595+ 0 : '0 - Unknown' ,
596+ 1 : '1 - Available state (not plugged in)' ,
597+ 2 : '2 - Preparing state of insertion (plugged in and not activated)' ,
598+ 3 : '3 - Charging state (charging with power output)' ,
599+ 4 : '4 - SuspendedEVSE pile Suspended at the terminal (already started but no available power)' ,
600+ 5 : '5 - SuspendedEV Suspended at the vehicle end (with available power, waiting for the car to respond)' ,
601+ 6 : '6 - Finishing The charging end state (actively swiping the card to stop or EMS stop control)' ,
602+ 7 : '7 - Unknown' ,
603+ 8 : '8 - Unknown' ,
604+ 9 : '9 - Faulted fault state (pile failure)'
605+ }
606+ } ]
561607 } ] ;
608+
562609 this . adapter = adapter ;
563610 this . emptyBody = { data : null } ;
564611 }
@@ -648,7 +695,7 @@ class OpenAPI {
648695 }
649696 }
650697 catch ( e ) {
651- this . adapter . log . error ( 'Reading data for group ' + group + ': Exception occurred: ' + e ) ;
698+ this . adapter . log . error ( 'Fetching data for group ' + group + ': Exception occurred: ' + e ) ;
652699 await this . handleError ( this . emptyBody , group ) ;
653700 }
654701 await this . startGroupTimeout ( group ) ;
@@ -674,7 +721,7 @@ class OpenAPI {
674721 }
675722 }
676723 catch ( e ) {
677- this . adapter . log . error ( 'Reading data for group ' + group + ': Exception occurred: ' + e ) ;
724+ this . adapter . log . error ( 'Fetching data for group ' + group + ': Exception occurred: ' + e ) ;
678725 await this . handleError ( this . emptyBody , group ) ;
679726 }
680727 await this . startGroupTimeout ( group ) ;
@@ -712,7 +759,7 @@ class OpenAPI {
712759 }
713760 }
714761 catch ( e ) {
715- this . adapter . log . error ( 'Reading data for group ' + group + ': Exception occurred: ' + e ) ;
762+ this . adapter . log . error ( 'Fetching data for group ' + group + ': Exception occurred: ' + e ) ;
716763 await this . handleError ( this . emptyBody , group ) ;
717764 }
718765 await this . startGroupTimeout ( group ) ;
@@ -736,7 +783,7 @@ class OpenAPI {
736783 }
737784 }
738785 catch ( e ) {
739- this . adapter . log . error ( 'Reading data for group ' + group + ': Exception occurred: ' + e ) ;
786+ this . adapter . log . error ( 'Fetching data for group ' + group + ': Exception occurred: ' + e ) ;
740787 await this . handleError ( this . emptyBody , group ) ;
741788 }
742789 await this . startGroupTimeout ( group ) ;
@@ -762,12 +809,77 @@ class OpenAPI {
762809 }
763810 }
764811 catch ( e ) {
765- this . adapter . log . error ( 'Reading data for group ' + group + ': Exception occurred: ' + e ) ;
812+ this . adapter . log . error ( 'Fetching data for group ' + group + ': Exception occurred: ' + e ) ;
766813 await this . handleError ( this . emptyBody , group ) ;
767814 }
768815 await this . startGroupTimeout ( group ) ;
769816 }
770817
818+ /**
819+ * @param {string } group
820+ */
821+ async getWallboxData ( group ) {
822+ try {
823+ this . adapter . stopGroupTimeout ( group ) ;
824+
825+ this . adapter . log . debug ( 'Fetching ' + group + ' data...' ) ;
826+
827+ // First we need to get SN if not already done:
828+ let snState = await this . adapter . getStateAsync ( `${ group } .SN` ) ;
829+ if ( ! snState || typeof snState . val === 'string' && snState . val . length == 0 ) {
830+ await this . getWallboxSn ( group ) ;
831+ this . adapter . log . info ( '###' + `${ group } .SN` ) ;
832+ snState = await this . adapter . getStateAsync ( `${ group } .SN` ) ;
833+ this . adapter . log . info ( '###' + `${ group } .SN` ) ;
834+ // In this special case we reset the creaton indicator because more states must be created for this group in the next step
835+ this . adapter . createdStates [ group ] = false ;
836+ }
837+
838+ if ( snState && typeof snState . val === 'string' && snState . val . length > 0 ) {
839+ this . adapter . log . debug ( `Using Wallbox SN: ${ snState . val } ` ) ;
840+ const res = await this . getRequest ( `getEvChargerStatusBySn?sysSn=${ this . adapter . config . systemId } &evchargerSn=${ snState . val } ` , { } ) ;
841+ if ( true || res && res [ 'status' ] == 200 && res . data && res . data . data ) {
842+ res . data . data = JSON . parse ( '{"evchargerStatus":1}' ) ;
843+ await this . adapter . createAndUpdateStates ( group , res . data . data ) ;
844+ }
845+ else {
846+ await this . handleError ( res , group ) ;
847+ }
848+ }
849+ else {
850+ this . adapter . log . error ( 'No wallbox SN could be found!' ) ;
851+ }
852+ }
853+ catch ( e ) {
854+ this . adapter . log . error ( 'Fetching data for group ' + group + ': Exception occurred: ' + e ) ;
855+ await this . handleError ( this . emptyBody , group ) ;
856+ }
857+ await this . startGroupTimeout ( group ) ;
858+ }
859+
860+ /**
861+ * @param {string } group
862+ */
863+ async getWallboxSn ( group ) {
864+ try {
865+ this . adapter . log . debug ( 'Fetching Wallbox SN ...' ) ;
866+
867+ const res = await this . getRequest ( `getEvChargerConfigList?sysSn=${ this . adapter . config . systemId } ` , { } ) ;
868+ if ( res && res [ 'status' ] == 200 && res . data && res . data . data ) {
869+
870+ res . data . data = JSON . parse ( '[{"evchargerSn":"ALP2021082015071x","evchargerModel":"SMILE-EVCT11"}]' ) ;
871+ await this . adapter . createAndUpdateStates ( group , res . data . data [ 0 ] ) ;
872+ }
873+ else {
874+ await this . handleError ( res , group ) ;
875+ }
876+ }
877+ catch ( e ) {
878+ this . adapter . log . error ( 'Fetching Wallbox SN: Exception occurred: ' + e ) ;
879+ await this . handleError ( this . emptyBody , group ) ;
880+ }
881+ }
882+
771883 /**
772884 * @param {string } group
773885 */
@@ -862,7 +974,11 @@ class OpenAPI {
862974 case 6010 : this . adapter . log . info ( `Error code: ${ res . data . code } - Sign is empty (#${ this . adapter . errorCount } )` ) ; break ;
863975 case 6011 : this . adapter . log . info ( `Error code: ${ res . data . code } - timestamp is empty (#${ this . adapter . errorCount } )` ) ; break ;
864976 case 6012 : this . adapter . log . info ( `Error code: ${ res . data . code } - AppId is empty (#${ this . adapter . errorCount } )` ) ; break ;
977+ case 6016 : this . adapter . log . info ( `Error code: ${ res . data . code } - Data does not exist or has been deleted (#${ this . adapter . errorCount } )` ) ; break ;
865978 case 6026 : this . adapter . log . info ( `Error code: ${ res . data . code } - Internal Error (#${ this . adapter . errorCount } )` ) ; break ;
979+ case 6029 : this . adapter . log . info ( `Error code: ${ res . data . code } - operation failed (#${ this . adapter . errorCount } )` ) ; break ;
980+ case 6038 : this . adapter . log . info ( `Error code: ${ res . data . code } - system sn does not exist (#${ this . adapter . errorCount } )` ) ; break ;
981+ case 6042 : this . adapter . log . info ( `Error code: ${ res . data . code } - system offline (#${ this . adapter . errorCount } )` ) ; break ;
866982 case 6046 : this . adapter . log . info ( `Error code: ${ res . data . code } - Verification code error (#${ this . adapter . errorCount } )` ) ; break ;
867983 case 6053 : this . adapter . log . info ( `Error code: ${ res . data . code } - The request was too fast, please try again later (#${ this . adapter . errorCount } )` ) ; break ;
868984 default : this . adapter . log . info ( `Error code: ${ res . data . code } - Unknown error (#${ this . adapter . errorCount } )` ) ;
@@ -2422,16 +2538,16 @@ class AlphaEss extends utils.Adapter {
24222538
24232539 // Create all states for received elements
24242540 for ( const [ alphaAttrName , rawValue ] of Object . entries ( data ) ) {
2425- const stateInfo = this . getStateInfoByAlphaAttrName ( group , alphaAttrName ) ;
2541+ const stateInfo = await this . getStateInfoByAlphaAttrName ( group , alphaAttrName ) ;
24262542 if ( typeof data [ alphaAttrName ] !== 'object' ) {
2427- this . createStateForAttribute ( group , data , rawValue , alphaAttrName , stateInfo , setObjectFunc ) ;
2543+ await this . createStateForAttribute ( group , data , rawValue , alphaAttrName , stateInfo , setObjectFunc ) ;
24282544 }
24292545 else {
24302546 // Look for subvalues:
24312547 if ( data [ alphaAttrName ] ) {
24322548 for ( const [ alphaAttrName2 , rawValue2 ] of Object . entries ( data [ alphaAttrName ] ) ) {
2433- const stateInfo2 = this . getStateInfoByAlphaAttrName ( group , alphaAttrName2 ) ;
2434- this . createStateForAttribute ( group , data [ alphaAttrName ] , rawValue2 , alphaAttrName2 , stateInfo2 , setObjectFunc ) ;
2549+ const stateInfo2 = await this . getStateInfoByAlphaAttrName ( group , alphaAttrName2 ) ;
2550+ await this . createStateForAttribute ( group , data [ alphaAttrName ] , rawValue2 , alphaAttrName2 , stateInfo2 , setObjectFunc ) ;
24352551 }
24362552 }
24372553 }
@@ -2442,16 +2558,16 @@ class AlphaEss extends utils.Adapter {
24422558
24432559 // Set values for received states
24442560 for ( const [ alphaAttrName , rawValue ] of Object . entries ( data ) ) {
2445- const stateInfo = this . getStateInfoByAlphaAttrName ( group , alphaAttrName ) ;
2561+ const stateInfo = await this . getStateInfoByAlphaAttrName ( group , alphaAttrName ) ;
24462562 if ( typeof data [ alphaAttrName ] !== 'object' ) {
2447- this . setValueForAttribute ( group , rawValue , stateInfo , idx ) ;
2563+ await this . setValueForAttribute ( group , rawValue , stateInfo , idx ) ;
24482564 }
24492565 else {
24502566 // Look for subvalues:
24512567 if ( data [ alphaAttrName ] ) {
24522568 for ( const [ alphaAttrName2 , rawValue2 ] of Object . entries ( data [ alphaAttrName ] ) ) {
2453- const stateInfo2 = this . getStateInfoByAlphaAttrName ( group , alphaAttrName2 ) ;
2454- this . setValueForAttribute ( group , rawValue2 , stateInfo2 , idx ) ;
2569+ const stateInfo2 = await this . getStateInfoByAlphaAttrName ( group , alphaAttrName2 ) ;
2570+ await this . setValueForAttribute ( group , rawValue2 , stateInfo2 , idx ) ;
24552571 }
24562572 }
24572573 }
@@ -2486,9 +2602,11 @@ class AlphaEss extends utils.Adapter {
24862602 , write : stateInfo . writeable ? stateInfo . writeable : false
24872603 , unit : stateInfo . unit === '{money_type}' ? data [ 'money_type' ] : stateInfo . unit === '{moneyType}' ? data [ 'moneyType' ] : stateInfo . unit
24882604 , desc : stateInfo . alphaAttrName
2605+ , states : stateInfo . states
24892606 } ,
24902607 native : { } ,
24912608 } ) ;
2609+ this . log . debug ( 'Created object ' + group + '.' + this . osn ( stateInfo . alphaAttrName ) + ' with value ' + rawValue ) ;
24922610 if ( stateInfo . writeable ) {
24932611 await this . subscribeStatesAsync ( `${ group } .${ stateInfo . id } ` ) ;
24942612 this . log . debug ( `Subscribed State: ${ group } .${ stateInfo . id } ` ) ;
@@ -2563,7 +2681,7 @@ class AlphaEss extends utils.Adapter {
25632681 * @param {string } Group
25642682 * @param {string } alphaAttrName
25652683 */
2566- getStateInfoByAlphaAttrName ( Group , alphaAttrName ) {
2684+ async getStateInfoByAlphaAttrName ( Group , alphaAttrName ) {
25672685 try {
25682686 const gidx = this . getStateInfoList ( ) . findIndex ( ( /** @type {{ Group: string; } } */ i ) => i . Group == Group ) ;
25692687 if ( gidx >= 0 ) {
@@ -2615,16 +2733,24 @@ class AlphaEss extends utils.Adapter {
26152733 */
26162734 async setQualityForGroup ( group , q ) {
26172735 try {
2618- const states = await this . getStatesAsync ( group + '.*' ) ;
2619- for ( const sid in states ) {
2620- const newState = states [ sid ] ;
2621- if ( newState . ack ) {
2622- newState . q = q ;
2623- this . log . debug ( `Set state ${ sid } to val: ${ newState . val } ; q: ${ newState . q } ; ack: ${ newState . ack } ` ) ;
2624- await this . setStateAsync ( sid , newState , true ) ;
2625- }
2626- else {
2627- this . log . debug ( `Set state ${ sid } NOT to val: ${ newState . val } ; q: ${ newState . q } because ack of this state is ${ newState . ack } ` ) ;
2736+ const gidx = this . getStateInfoList ( ) . findIndex ( ( /** @type {{ Group: string; } } */ i ) => i . Group == group ) ;
2737+ if ( gidx >= 0 ) {
2738+ const groupInfo = this . getStateInfoList ( ) [ gidx ] ;
2739+ const groupStates = groupInfo . states ;
2740+ for ( let i = 0 ; i < groupStates . length ; i ++ ) {
2741+ if ( ! groupStates [ i ] . isStatic ) {
2742+ const newState = await this . getStateAsync ( `${ groupInfo . Group } .${ groupStates [ i ] . id } ` ) ;
2743+ if ( newState ) {
2744+ if ( newState . ack ) {
2745+ newState . q = q ;
2746+ this . log . debug ( `Set state ${ groupInfo . Group } .${ groupStates [ i ] . id } to val: ${ newState . val } ; q: ${ newState . q } ; ack: ${ newState . ack } ` ) ;
2747+ await this . setStateAsync ( `${ groupInfo . Group } .${ groupStates [ i ] . id } ` , newState , true ) ;
2748+ }
2749+ else {
2750+ this . log . debug ( `Set state ${ groupInfo . Group } .${ groupStates [ i ] . id } NOT to val: ${ newState . val } ; q: ${ newState . q } because ack of this state is ${ newState . ack } ` ) ;
2751+ }
2752+ }
2753+ }
26282754 }
26292755 }
26302756 }
@@ -2645,7 +2771,7 @@ class AlphaEss extends utils.Adapter {
26452771 const groupInfo = this . getStateInfoList ( ) [ gidx ] ;
26462772 const groupStates = groupInfo . states ;
26472773 for ( let i = 0 ; i < groupStates . length ; i ++ ) {
2648- if ( groupStates [ i ] . lastUpdateTs ) {
2774+ if ( groupStates [ i ] . lastUpdateTs && ! groupStates [ i ] . isStatic ) {
26492775 if ( Date . now ( ) - groupStates [ i ] . lastUpdateTs > ( groupInfo . interval * 1000 + REQUEST_TIMEOUT ) ) {
26502776 const newState = await this . getStateAsync ( `${ groupInfo . Group } .${ groupStates [ i ] . id } ` ) ;
26512777 if ( newState ) {
0 commit comments