5 Commits
Author SHA1 Message Date
HassBox c12e77d4e6 . 2024-05-08 08:01:34 +08:00
HassBox ba103f293c . 2024-05-06 23:15:45 +08:00
HassBox b116ef701f . 2024-05-06 23:14:13 +08:00
HassBox ebcfbb0935 . 2024-05-06 10:02:29 +08:00
HassBox 806c44e174 . 2024-05-06 09:37:57 +08:00
9 changed files with 458 additions and 449 deletions
@@ -139,6 +139,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
else: else:
self.data_client.refresh_interval = int(user_input['refresh_interval']) self.data_client.refresh_interval = int(user_input['refresh_interval'])
self.data_client.is_debug = user_input['is_debug'] self.data_client.is_debug = user_input['is_debug']
await self.data_client.save_data()
return self.async_create_entry( return self.async_create_entry(
title="国家电网", title="国家电网",
data={} data={}
+2 -2
View File
@@ -1,4 +1,4 @@
DOMAIN = "state_grid" DOMAIN = 'state_grid'
PACKAGE_NAME = "custom_components.state_grid" PACKAGE_NAME = "custom_components.state_grid"
VERSION = "0.0.6" VERSION = "0.0.4"
VERSION_STORAGE = 1 VERSION_STORAGE = 1
+318 -304
View File
@@ -1,331 +1,345 @@
_Al='queryYear' BZ='params4'
_Ak='provinceCode' BY='params3'
_Aj='sceneType' BX='params1'
_Ai='consNoSrc' BW='queryYear'
_Ah='access_token' BV='provinceCode'
_Ag='businessType' BU='sceneType'
_Af='qrCodeSerial' BT='consNoSrc'
_Ae='redirect_url' BS='access_token'
_Ad='_access_token' BR='codeKey'
_Ac='refresh_interval' BQ='businessType'
_Ab='doorAccountDict' BP='Channels'
_Aa='refreshToken' BO='qrCodeSerial'
_AZ='accessToken' BN='redirect_url'
_AY='/osg-web0004/member/c24/f01' BM='_access_token'
_AX='BCP_00026' BL='is_debug'
_AW='serviceCode_smt' BK='refresh_interval'
_AV='WEBA10070900' BJ='doorAccountDict'
_AU='serviceType' BI='refreshToken'
_AT='jM_custType' BH='accessToken'
_AS='jM_busiTypeCode' BG='/osg-web0004/member/c24/f01'
_AR='consType' BF='BCP_00026'
_AQ='constType' BE='serviceCode_smt'
_AP='powerUserList' BD='WEBA10070900'
_AO='publicKey' BC='serviceType'
_AN='WEBA10070800' BB='jM_custType'
_AM='timeDay' BA='jM_busiTypeCode'
_AL='WEBA10070700' B9='01008183'
_AK='0101143' B8='0101003'
_AJ='channelNo' B7='submit'
_AI='latestBillMonth' B2='consType'
_AH='yearTotalCost' B1='constType'
_AG='userAccountId' B0='powerUserList'
_AF='0000' A_='publicKey'
_AE='refresh_token' Az='WEBA10070800'
_AD='skey' Ay='timeDay'
_AC='userInfo' Ax='105'
_AB='0101046' Aw='111'
_AA='proCode' Av='0901'
_A9='loginAccount' Au='WEBA10070700'
_A8='keyCode' At='102'
_A7='querytypeCode' As='0101143'
_A6='01010049' Ar='channelNo'
_A5='doorNumberManeger' Ae='latestBillMonth'
_A4='monthBillList' Ad='yearTotalCost'
_A3='accountBalance' Ac='userAccountId'
_A2='list' Ab='0000'
_A1='userName' Aa='refresh_token'
_A0='acctId' AZ='web'
_z='resultCode' AY='skey'
_y='quInfo' AX='userInfo'
_x='BCP_000026' AW=True
_w='app' AV='215'
_v='WEBALIPAY_01' AU='0101046'
_u='order' AK='accountBalance'
_t='state_grid' AJ='proCode'
_s=False AI='loginAccount'
_r='authFlag' AH='keyCode'
_q='09' AG='querytypeCode'
_p='0101183' AF='01010049'
_o='stepelect' AE='doorNumberManeger'
_n='account' AD='monthBillList'
_m='consNo_dst' AC='list'
_l='token' AB='userName'
_k='0101154' AA='acctId'
_j='getday' A9='resultCode'
_i='consNo' A8='quInfo'
_h='bizrt' A7='BCP_000026'
_g='clearCache' A6='app'
_f='timestamp' A5='WEBALIPAY_01'
_e='errmsg' A4='order'
_d='promotCode' A3='state_grid'
_c='01' z=False
_b='SGAPP' y='authFlag'
_a='devciceId' x='09'
_Z='devciceIp' w='0101183'
_Y='orgNo' v='stepelect'
_X='tenant' u='account'
_W='member' t=len
_V='daily_bill_list' s='consNo_dst'
_U='proNo' r='token'
_T='promotType' q='0101154'
_S='target' p='getday'
_R='userId' n='consNo'
_Q='srvrt' m='bizrt'
_P='subBusiTypeCode' l='clearCache'
_O='serCat' k='timestamp'
_N='serialNo' i='errmsg'
_M='0902' h='promotCode'
_L='srvCode' g='01'
_K='uscInfo' f='SGAPP'
_J=None e='devciceId'
_I='busiTypeCode' d='devciceIp'
_H='code' c='orgNo'
_G='channelCode' b='tenant'
_F='1' a='member'
_E='source' Z=str
_D='funcCode' Y='daily_bill_list'
_C='serviceCode' X='proNo'
_B='errcode' W='promotType'
_A='data' V='target'
import json,time,aiohttp,urllib.parse,datetime U='userId'
from.utils.logger import LOGGER T='srvrt'
from.utils.store import async_save_to_store S='subBusiTypeCode'
from.utils.crypt import a,b,c,d,e R='serCat'
appKey='3def6c365d284881bf1a9b2b502ee68c' Q='serialNo'
appSecret='ab7357dae64944a197ace37398897f64' O='0902'
configuration={_K:{_W:_M,_Z:'',_a:'',_X:_t},_E:_b,_S:'32101',_G:_M,_AJ:_M,'toPublish':_c,'siteId':'2012000000033700',_L:'',_N:'',_D:'',_C:{_u:_k,'uploadPic':'0101296','pauseSCode':'0101250','pauseTCode':'0101251','listconsumers':'0101093','messageList':'0101343','submit':'0101003','sbcMsg':'0101210','powercut':'0104514','BkAuth01':'f15','BkAuth02':'f18','BkAuth03':'f02','BkAuth04':'f17','BkAuth05':'f05','BkAuth06':'f16','BkAuth07':'f01','BkAuth08':'f03'},'electricityArchives':{'servicecode':'0104505',_E:_M},'subscriptionList':{_L:'APP_SGPMS_05_030',_N:'22',_G:_M,_D:'22',_S:'-1'},'userInformation':{_C:'01008183',_E:_b},'userInform':{_C:_p,_E:_b},'elesum':{_G:_M,_D:_v,_d:_F,_T:_F,_C:_AK,_E:_w},_n:{_G:_M,_D:'WEBA1007200'},_A5:{_E:_M,_S:'-1',_G:_q,_AJ:_q,_C:_A6,_D:'WEBA40050000',_K:{_W:_M,_Z:'',_a:'',_X:_t}},'doorAuth':{_E:_b,_C:'f04'},'xinZ':{_O:'101',_AS:'101','fJ_busiTypeCode':'102',_AT:'03','fJ_custType':'02',_AU:_c,_P:'',_D:_AL,_u:_k,_E:_b,_A7:_F},'onedo':{_C:_AB,_E:_b,_D:_AL,'queryType':'03'},'xinHuTongDian':{_O:'110',_I:'211',_P:'21102',_D:'WEBA10071200',_G:_M,_E:_q,_C:_p},'company':{_O:'104',_D:_AL,_AU:'02',_A7:_F,_r:_F,_E:_b,_u:_k},'charge':{_G:_q,_D:'WEBA10071300',_AJ:'0901',_O:'102',_AT:_c,_AS:'102'},'other':{_G:_q,_D:'WEBA10079700',_O:'129',_I:'999',_P:'21501',_C:_x,_L:'',_N:''},'vatchange':{'submit':'0101003',_I:'320',_P:'',_O:'115',_D:'WEBA10074000',_r:_F},'bill':{_g:_F,_D:_v,_T:_F,_C:_x},_o:{_G:_M,_D:_v,_T:_F,_g:_q,_C:_x,_E:_w},_j:{_G:_M,_g:'11',_D:_v,_d:_F,_T:_F,_C:_x,_E:_w},'mouthOut':{_G:_M,_g:'11',_D:_v,_d:_F,_T:_F,_C:_x,_E:_w},'meter':{_O:'114',_I:'304',_D:'WEBA10071000',_P:'',_C:_AB,_N:''},'complaint':{_I:'005','srvMode':_M,'anonymousFlag':'0','replyMode':_c,'retvisitFlag':_c},'report':{_I:'006'},'tradewinds':{_I:'019'},'somesay':{_I:'091'},'faultrepair':{_D:_AV,_C:_p,_O:'111',_I:'001',_P:'21505'},'electronicInvoice':{_O:'105',_I:'0'},'rename':{_C:_AB,_D:'WEBA10076100',_I:'210',_O:'109',_r:_F,'gh_busiTypeCode':'211','gh_subusi':'21101',_N:'',_L:''},'pause':{_P:'',_C:_A6,_D:'WEBA10073600',_O:'107',_I:'203','jr_busi':'201',_N:'',_L:''},'capacityRecovery':{_C:_A6,_E:_b,_L:'',_N:'',_D:'WEBA10073700','busiTypeCode_stop':'204','busiTypeCode_less':'202',_I:'202',_P:'',_O:'108',_AM:'5',_r:_F},'electricityPriceChange':{_C:_p,_I:'215',_P:'21502',_O:'113',_r:_F,_AM:'15',_D:'WEBA10073900WEB',_L:'',_N:''},'electricityPriceStrategyChange':{_C:'01008183',_I:'215',_P:'21506',_O:'160',_D:'WEBV00000517WEB',_L:'',_N:''},'eemandValueAdjustment':{_C:_p,_L:'',_N:'',_O:'112',_D:'WEBA10073800',_I:'215',_P:'21504',_r:_F,_AM:'5','getMonthServiceCode':_AB},'businessProgress':{_C:_p,_L:_c,_D:'WEB01'},'increase':{_E:_b,_N:'',_L:'',_AW:_A6,_C:_k,_u:_k,_D:_AN,_A7:_F,_O:'106',_I:'111',_P:''},'fjincrea':{_O:'105',_I:'110',_P:'',_E:_b,_D:_AN,_N:'',_L:'',_AW:_A6,_C:_k,_u:_k,_A7:_F},'persIncrea':{_O:'105',_I:'109',_u:_k,_P:'',_E:_b,_D:_AN,_A7:_F},'fgdChange':{_C:_p,_L:_c,_G:_q,_D:_AV,_I:'215',_P:'21505',_O:'111',_r:_F},'createOrder':{_G:_M,_D:_v,_L:'BCP_000001','chargeMode':'02','conType':_c,'bizTypeId':'BT_ELEC'},'largePopulation':{_I:'383',_D:'WEBA10076800',_P:'',_L:'',_T:'',_d:'',_G:'0901',_O:'383',_C:'',_N:''},'biaoJiCode':{_C:'0104507',_E:'1704',_G:'1704'},'twoGuar':{_I:'402',_P:'40201',_D:'web_twoGuar'},'electTrend':{_C:_AX,_G:_M},'emergency':{_C:_AX,_D:'A10000000',_G:_M},'infoPublic':{_C:'2545454',_E:_w}} N='srvCode'
baseApi='https://www.95598.cn/api' M='uscInfo'
get_request_key_api='/oauth2/outer/c02/f02' L=None
get_qr_code_api='/osg-open-uc0001/member/c8/f24' K='busiTypeCode'
get_qr_code_status_api='/osg-web0004/open/c50/f02' J='code'
get_qr_code_token_api='/osg-uc0013/member/c4/f04' I='channelCode'
send_code_api='/osg-open-uc0001/member/c8/f04' H='1'
code_login_api='/osg-uc0013/member/c4/f02' G='source'
getCertificationApi='/osg-open-uc0001/member/c8/f11' E='funcCode'
get_request_authorize_api='/oauth2/oauth/authorize' D='serviceCode'
get_web_token_api='/oauth2/outer/getWebToken' C='errcode'
refresh_web_token_api='/oauth2/outer/refresh_web_token' B='data'
get_door_number_api='/osg-open-uc0001/member/c9/f02' A=''
get_door_balance_api='/osg-open-bc0001/member/c05/f01' import json as AL,time as Af,aiohttp as Ag,urllib.parse,datetime as j
get_door_bill_api='/osg-open-bc0001/member/c01/f02' from.utils.logger import LOGGER as A0
get_door_ladder_api='/osg-open-bc0001/member/c04/f03' from.utils.store import async_save_to_store as Ba
getJiaoFeiRecordApi=_AY from.utils.crypt import a as AM,b as B3,c as A1,d as AN,e as Ah
get_door_daily_bill_api=_AY o='3def6c365d284881bf1a9b2b502ee68c'
sessionIdControlApiList=[get_qr_code_api,get_qr_code_status_api,get_qr_code_token_api,send_code_api,code_login_api] Ai='ab7357dae64944a197ace37398897f64'
keyCodeControlApiList=[get_qr_code_status_api,get_qr_code_token_api,send_code_api,code_login_api,getCertificationApi,get_request_authorize_api,get_web_token_api,refresh_web_token_api,get_door_number_api,get_door_balance_api,get_door_bill_api,get_door_ladder_api,getJiaoFeiRecordApi,get_door_daily_bill_api] F={M:{a:O,d:A,e:A,b:A3},G:f,V:'32101',I:O,Ar:O,'toPublish':g,'siteId':'2012000000033700',N:A,Q:A,E:A,D:{A4:q,'uploadPic':'0101296','pauseSCode':'0101250','pauseTCode':'0101251','listconsumers':'0101093','messageList':'0101343',B7:B8,'sbcMsg':'0101210','powercut':'0104514','BkAuth01':'f15','BkAuth02':'f18','BkAuth03':'f02','BkAuth04':'f17','BkAuth05':'f05','BkAuth06':'f16','BkAuth07':'f01','BkAuth08':'f03'},'electricityArchives':{'servicecode':'0104505',G:O},'subscriptionList':{N:'APP_SGPMS_05_030',Q:'22',I:O,E:'22',V:'-1'},'userInformation':{D:B9,G:f},'userInform':{D:w,G:f},'elesum':{I:O,E:A5,h:H,W:H,D:As,G:A6},u:{I:O,E:'WEBA1007200'},AE:{G:O,V:'-1',I:x,Ar:x,D:AF,E:'WEBA40050000',M:{a:O,d:A,e:A,b:A3}},'doorAuth':{G:f,D:'f04'},'xinZ':{R:'101',BA:'101','fJ_busiTypeCode':At,BB:'03','fJ_custType':'02',BC:g,S:A,E:Au,A4:q,G:f,AG:H},'onedo':{D:AU,G:f,E:Au,'queryType':'03'},'xinHuTongDian':{R:'110',K:'211',S:'21102',E:'WEBA10071200',I:O,G:x,D:w},'company':{R:'104',E:Au,BC:'02',AG:H,y:H,G:f,A4:q},'charge':{I:x,E:'WEBA10071300',Ar:Av,R:At,BB:g,BA:At},'other':{I:x,E:'WEBA10079700',R:'129',K:'999',S:'21501',D:A7,N:A,Q:A},'vatchange':{B7:B8,K:'320',S:A,R:'115',E:'WEBA10074000',y:H},'bill':{l:H,E:A5,W:H,D:A7},v:{I:O,E:A5,W:H,l:x,D:A7,G:A6},p:{I:O,l:'11',E:A5,h:H,W:H,D:A7,G:A6},'mouthOut':{I:O,l:'11',E:A5,h:H,W:H,D:A7,G:A6},'meter':{R:'114',K:'304',E:'WEBA10071000',S:A,D:AU,Q:A},'complaint':{K:'005','srvMode':O,'anonymousFlag':'0','replyMode':g,'retvisitFlag':g},'report':{K:'006'},'tradewinds':{K:'019'},'somesay':{K:'091'},'faultrepair':{E:BD,D:w,R:Aw,K:'001',S:'21505'},'electronicInvoice':{R:Ax,K:'0'},'rename':{D:AU,E:'WEBA10076100',K:'210',R:'109',y:H,'gh_busiTypeCode':'211','gh_subusi':'21101',Q:A,N:A},'pause':{S:A,D:AF,E:'WEBA10073600',R:'107',K:'203','jr_busi':'201',Q:A,N:A},'capacityRecovery':{D:AF,G:f,N:A,Q:A,E:'WEBA10073700','busiTypeCode_stop':'204','busiTypeCode_less':'202',K:'202',S:A,R:'108',Ay:'5',y:H},'electricityPriceChange':{D:w,K:AV,S:'21502',R:'113',y:H,Ay:'15',E:'WEBA10073900WEB',N:A,Q:A},'electricityPriceStrategyChange':{D:B9,K:AV,S:'21506',R:'160',E:'WEBV00000517WEB',N:A,Q:A},'eemandValueAdjustment':{D:w,N:A,Q:A,R:'112',E:'WEBA10073800',K:AV,S:'21504',y:H,Ay:'5','getMonthServiceCode':AU},'businessProgress':{D:w,N:g,E:'WEB01'},'increase':{G:f,Q:A,N:A,BE:AF,D:q,A4:q,E:Az,AG:H,R:'106',K:Aw,S:A},'fjincrea':{R:Ax,K:'110',S:A,G:f,E:Az,Q:A,N:A,BE:AF,D:q,A4:q,AG:H},'persIncrea':{R:Ax,K:'109',A4:q,S:A,G:f,E:Az,AG:H},'fgdChange':{D:w,N:g,I:x,E:BD,K:AV,S:'21505',R:Aw,y:H},'createOrder':{I:O,E:A5,N:'BCP_000001','chargeMode':'02','conType':g,'bizTypeId':'BT_ELEC'},'largePopulation':{K:'383',E:'WEBA10076800',S:A,N:A,W:A,h:A,I:Av,R:'383',D:A,Q:A},'biaoJiCode':{D:'0104507',G:'1704',I:'1704'},'twoGuar':{K:'402',S:'40201',E:'web_twoGuar'},'electTrend':{D:BF,I:O},'emergency':{D:BF,E:'A10000000',I:O},'infoPublic':{D:'2545454',G:A6}}
authControlApiList=[get_door_number_api,get_door_balance_api,get_door_bill_api,get_door_ladder_api,getJiaoFeiRecordApi,get_door_daily_bill_api] B4='https://www.95598.cn/api'
tControlApiList=[getCertificationApi,get_door_balance_api,get_door_bill_api,get_door_ladder_api,getJiaoFeiRecordApi,get_door_daily_bill_api] B5='/oauth2/outer/c02/f02'
def json_dumps(data):return json.dumps(data,separators=(',',':'),ensure_ascii=_s) Aj='/osg-open-uc0001/member/c8/f24'
def catchFloat(data,key): Ak='/osg-web0004/open/c50/f02'
Al='/osg-uc0013/member/c4/f04'
Am='/osg-open-uc0001/member/c8/f04'
An='/osg-uc0013/member/c4/f02'
B6='/osg-open-uc0001/member/c8/f11'
Ao='/oauth2/oauth/authorize'
AO='/oauth2/outer/getWebToken'
Ap='/oauth2/outer/refresh_web_token'
Aq='/osg-open-uc0001/member/c9/f02'
AP='/osg-open-bc0001/member/c05/f01'
AQ='/osg-open-bc0001/member/c01/f02'
AR='/osg-open-bc0001/member/c04/f03'
AS=BG
AT=BG
Bb=[Aj,Ak,Al,Am,An]
Bc=[Ak,Al,Am,An,B6,Ao,AO,Ap,Aq,AP,AQ,AR,AS,AT]
Bd=[Aq,AP,AQ,AR,AS,AT]
Be=[B6,AP,AQ,AR,AS,AT]
def A2(data):return AL.dumps(data,separators=(',',':'),ensure_ascii=z)
def P(data,key):
if key in data: if key in data:
try:return float(data[key]) try:return float(data[key])
except:return 0 except:return 0
else:return 0 else:return 0
class StateGridDataClient: class StateGridDataClient:
hass=_J;session=_J;keyCode=_J;publicKey=_J;need_login=_s;phone=_J;codeKey=_J;serialNo=_J;qrCodeSerial=_J;userInfo=_J;accountInfo=_J;powerUserList=_J;doorAccountDict={};cookie=[];timestamp=int(time.time()*1000);accessToken=_J;refreshToken=_J;token=_J;expirationDate=_J;refresh_interval=12;is_debug=_s hass=L;session=L;keyCode=L;publicKey=L;need_login=z;phone=L;codeKey=L;serialNo=L;qrCodeSerial=L;userInfo=L;accountInfo=L;powerUserList=L;doorAccountDict={};cookie=[];timestamp=int(Af.time()*1000);accessToken=L;refreshToken=L;token=L;expirationDate=L;refresh_interval=12;is_debug=z
def __init__(A,hass,config=_J): def __init__(A,hass,config=L):
B=config;A.hass=hass;C=aiohttp.TCPConnector(ssl=_s);D=aiohttp.CookieJar(quote_cookie=True);A.session=aiohttp.ClientSession(cookie_jar=D,connector=C) B=config;A.hass=hass;C=Ag.TCPConnector(ssl=z);D=Ag.CookieJar(quote_cookie=AW);A.session=Ag.ClientSession(cookie_jar=D,connector=C)
if B is not _J: if B is not L:
try:A.keyCode=B[_A8];A.publicKey=B[_AO];A.accessToken=B[_AZ];A.refreshToken=B[_Aa];A.token=B[_l];A.userInfo=B[_AC];A.powerUserList=B[_AP];A.doorAccountDict=B[_Ab];A.refresh_interval=B[_Ac];A.is_debug=B['is_debug'] try:A.keyCode=B[AH];A.publicKey=B[A_];A.accessToken=B[BH];A.refreshToken=B[BI];A.token=B[r];A.userInfo=B[AX];A.powerUserList=B[B0];A.doorAccountDict=B[BJ];A.refresh_interval=B[BK];A.is_debug=B[BL]
except Exception as E:LOGGER.error(E) except Exception as E:A0.error(E)
async def save_data(A):B={};B[_A8]=A.keyCode;B[_AO]=A.publicKey;B[_AZ]=A.accessToken;B[_Aa]=A.refreshToken;B[_l]=A.token;B[_AC]=A.userInfo;B[_AP]=A.powerUserList;B[_Ab]=A.doorAccountDict;B[_Ac]=A.refresh_interval;B['is_debug']=A.is_debug;await async_save_to_store(A.hass,'state_grid.config',B) async def save_data(A):B={};B[AH]=A.keyCode;B[A_]=A.publicKey;B[BH]=A.accessToken;B[BI]=A.refreshToken;B[r]=A.token;B[AX]=A.userInfo;B[B0]=A.powerUserList;B[BJ]=A.doorAccountDict;B[BK]=A.refresh_interval;B[BL]=A.is_debug;await Ba(A.hass,'state_grid.config',B)
def encrypt_post_data(A,data):B={_Ad:A.accessToken[len(A.accessToken)//2:]if A.accessToken else'','_t':A.token[len(A.token)//2:]if A.token else'','_data':data,_f:A.timestamp};return A.encrypt_wapper_data(B) def encrypt_post_data(B,data):C={BM:B.accessToken[t(B.accessToken)//2:]if B.accessToken else A,'_t':B.token[t(B.token)//2:]if B.token else A,'_data':data,k:B.timestamp};return B.encrypt_wapper_data(C)
def encrypt_wapper_data(A,data):B=a(json_dumps(data),A.keyCode);return{_A:B+c(B+str(A.timestamp)),_AD:d(A.keyCode,A.publicKey),_f:str(A.timestamp)} def encrypt_wapper_data(A,data):C=AM(A2(data),A.keyCode);return{B:C+A1(C+Z(A.timestamp)),AY:AN(A.keyCode,A.publicKey),k:Z(A.timestamp)}
def handle_request_result_message(E,api,result): def handle_request_result_message(F,api,result):
D='message';C='resultMessage';A=result;B=_J E='message';D='resultMessage';A=result;C=L
if _A in A and _Q in A[_A]and C in A[_A][_Q]:B=A[_A][_Q][C] if B in A and T in A[B]and D in A[B][T]:C=A[B][T][D]
elif _Q in A and C in A[_Q]:B=A[_Q][C] elif T in A and D in A[T]:C=A[T][D]
elif D in A:B=A[D] elif E in A:C=A[E]
else:B=json_dumps(A) else:C=A2(A)
if E.is_debug:LOGGER.error(api+': '+B);LOGGER.error(json_dumps(A)) if F.is_debug:A0.error(api+': '+C);A0.error(A2(A))
return B
async def fetch(B,api,data,header=_J):
T='encryptData';S='464606a4-184c-4beb-b442-2ab7761d0796';R='key_code';Q='state';P='sign';O='grant_type';N='application/json;charset=UTF-8';M='Content-Type';L=header;K='client_secret';I='client_id';E=api;B.timestamp=int(time.time()*1000);D=B.timestamp
if B.keyCode is _J:B.keyCode=e(32,16,2)
F=B.keyCode;G={'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Mobile Safari/537.36','Accept':N,M:N,'version':'1.0',_E:'0901',_f:str(D),'wsgwType':'web','appKey':appKey};A=data
if E==get_request_key_api:A={I:appKey,K:appSecret};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AD:d(F,'042BC7AD510BF9793B7744C8854C56A8C95DD1027EE619247A332EC6ED5B279F435A23D62441FE861F4B0C963347ECD5792F380B64CA084BE8BE41151F8B8D19C8'),I:appKey,_f:str(D)}
elif E==get_qr_code_api:A={_Ad:'','_t':'','_data':A,_f:D}
elif E==get_request_authorize_api:
A={I:appKey,'response_type':_H,_Ae:'/test',_f:D,'rsi':B.token};A=urllib.parse.urlencode(A);G[M]='application/x-www-form-urlencoded; charset=UTF-8';G[_A8]=F
async with B.session.post(baseApi+E,data=A,headers=G)as J:B.session.cookie_jar.update_cookies(J.cookies);C=await J.json();C=b(C[_A],B.token);C=json.loads(C);return C
elif E==get_web_token_api:A={O:'authorization_code',P:c(appKey+str(D)),K:appSecret,Q:S,R:F,I:appKey,_f:D,_H:A[_H]};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AD:d(F,B.publicKey),_f:str(D)}
elif E==refresh_web_token_api:A={O:_AE,P:c(appKey+str(D)),K:appSecret,Q:S,R:F,I:appKey,_f:D,_AE:B.refreshToken};H=a(json_dumps(A),F);A={_A:H+c(H+str(D)),_AD:d(F,B.publicKey),_f:str(D)};E=get_web_token_api
else:A=B.encrypt_post_data(A)
if L is not _J:G.update(L)
if E in sessionIdControlApiList:G['sessionId']='web'+str(D)
if E in keyCodeControlApiList:G[_A8]=F
if E in authControlApiList:G['Authorization']='Bearer '+B.accessToken[:len(B.accessToken)//2]
if E in tControlApiList:G['t']=B.token[:len(B.token)//2]
async with B.session.post(baseApi+E,json=A,headers=G)as J:
C=await J.text()
if C.startswith('{'):
C=json.loads(C)
if T in C:C=b(C[T],F);C=json.loads(C)
return C return C
async def fetch(D,api,data,header=L):
Y='encryptData';X='464606a4-184c-4beb-b442-2ab7761d0796';W='key_code';V='state';U='sign';T='grant_type';S='application/json;charset=UTF-8';R='Content-Type';Q=header;P='client_secret';N='client_id';H=api;D.timestamp=int(Af.time()*1000);F=D.timestamp
if D.keyCode is L:D.keyCode=Ah(32,16,2)
I=D.keyCode;K={'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Mobile Safari/537.36','Accept':S,R:S,'version':'1.0',G:Av,k:Z(F),'wsgwType':AZ,'appKey':o};C=data
if H==B5:C={N:o,P:Ai};M=AM(A2(C),I);C={B:M+A1(M+Z(F)),AY:AN(I,'042BC7AD510BF9793B7744C8854C56A8C95DD1027EE619247A332EC6ED5B279F435A23D62441FE861F4B0C963347ECD5792F380B64CA084BE8BE41151F8B8D19C8'),N:o,k:Z(F)}
elif H==Aj:C={BM:A,'_t':A,'_data':C,k:F}
elif H==Ao:
C={N:o,'response_type':J,BN:'/test',k:F,'rsi':D.token};C=urllib.parse.urlencode(C);K[R]='application/x-www-form-urlencoded; charset=UTF-8';K[AH]=I
async with D.session.post(B4+H,data=C,headers=K)as O:D.session.cookie_jar.update_cookies(O.cookies);E=await O.json();E=B3(E[B],D.token);E=AL.loads(E);return E
elif H==AO:C={T:'authorization_code',U:A1(o+Z(F)),P:Ai,V:X,W:I,N:o,k:F,J:C[J]};M=AM(A2(C),I);C={B:M+A1(M+Z(F)),AY:AN(I,D.publicKey),k:Z(F)}
elif H==Ap:C={T:Aa,U:A1(o+Z(F)),P:Ai,V:X,W:I,N:o,k:F,Aa:D.refreshToken};M=AM(A2(C),I);C={B:M+A1(M+Z(F)),AY:AN(I,D.publicKey),k:Z(F)};H=AO
else:C=D.encrypt_post_data(C)
if Q is not L:K.update(Q)
if H in Bb:K['sessionId']=AZ+Z(F)
if H in Bc:K[AH]=I
if H in Bd:K['Authorization']='Bearer '+D.accessToken[:t(D.accessToken)//2]
if H in Be:K['t']=D.token[:t(D.token)//2]
async with D.session.post(B4+H,json=C,headers=K)as O:
E=await O.text()
if E.startswith('{'):
E=AL.loads(E)
if Y in E:E=B3(E[Y],I);E=AL.loads(E)
return E
async def __get_request_key(A): async def __get_request_key(A):
A.keyCode=_J;B=await A.fetch(get_request_key_api,{});C=A.handle_request_result_message('get_request_key_api',B) A.keyCode=L;D=await A.fetch(B5,{});E=A.handle_request_result_message('get_request_key_api',D)
if B[_H]==_F:A.keyCode=B[_A][_A8];A.publicKey=B[_A][_AO];return{_B:0} if D[J]==H:A.keyCode=D[B][AH];A.publicKey=D[B][A_];return{C:0}
return{_B:1,_e:C} return{C:1,i:E}
async def __get_qr_code(B): async def __get_qr_code(E):
C={_K:{_Z:'',_X:_t,_W:_M,_a:''},_y:{'optType':_c,_N:e(28,10,1)}};A=await B.fetch(get_qr_code_api,C);D=B.handle_request_result_message('get_qr_code_api',A) F={M:{d:A,b:A3,a:O,e:A},A8:{'optType':g,Q:Ah(28,10,1)}};D=await E.fetch(Aj,F);G=E.handle_request_result_message('get_qr_code_api',D)
if A[_H]==1: if D[J]==1:
if A[_A]and A[_A][_Q]and A[_A][_Q][_z]==_AF:B.qrCodeSerial=A[_A][_h][_Af];E=A[_A][_h]['qrCode'];return{_B:0,_A:E} if D[B]and D[B][T]and D[B][T][A9]==Ab:E.qrCodeSerial=D[B][m][BO];H=D[B][m]['qrCode'];return{C:0,B:H}
return{_B:1,_e:D} return{C:1,i:G}
async def __get_qr_code_status(B): async def __get_qr_code_status(D):
C={_h:{_Af:B.qrCodeSerial}};D={_l:'98'+e(10,10,1)};A=await B.fetch(get_qr_code_status_api,C,D);E=B.handle_request_result_message('get_qr_code_status_api',A) E={m:{BO:D.qrCodeSerial}};F={r:'98'+Ah(10,10,1)};A=await D.fetch(Ak,E,F);G=D.handle_request_result_message('get_qr_code_status_api',A)
if _H in A and A[_H]==1: if J in A and A[J]==1:
if _A in A and A[_A]!='null':B.token=A[_A];return{_B:0} if B in A and A[B]!='null':D.token=A[B];return{C:0}
else:return{_B:1,_e:'未使用网上国网 App 扫码或确认登录'} else:return{C:1,i:'未使用网上国网 App 扫码或确认登录'}
return{_B:1,_e:E} return{C:1,i:G}
async def __get_qr_code_token(B): async def __get_qr_code_token(B):
C={_K:{_X:_t,_W:_M,'isEncrypt':True},_l:B.token};A=await B.fetch(get_qr_code_token_api,C);D=B.handle_request_result_message('get_qr_code_token_api',A) D={M:{b:A3,a:O,'isEncrypt':AW},r:B.token};A=await B.fetch(Al,D);E=B.handle_request_result_message('get_qr_code_token_api',A)
if _Q in A and _z in A[_Q]and A[_Q][_z]==_AF:B.userInfo=A[_h][_AC];return{_B:0} if T in A and A9 in A[T]and A[T][A9]==Ab:B.userInfo=A[m][AX];return{C:0}
return{_B:1,_e:D} return{C:1,i:E}
async def __send_code(B,phone): async def __send_code(E,phone):
C=phone;B.phone=C;D={_K:{_Z:'',_X:_t,_W:_M,_a:''},_y:{'sendType':'0',_n:C,_Ag:'login','accountType':''},'Channels':'web'};A=await B.fetch(send_code_api,D);E=B.handle_request_result_message('send_code_api',A) F=phone;E.phone=F;G={M:{d:A,b:A3,a:O,e:A},A8:{'sendType':'0',u:F,BQ:'login','accountType':A},BP:AZ};D=await E.fetch(Am,G);H=E.handle_request_result_message('send_code_api',D)
if A[_H]==1: if D[J]==1:
if A[_A]and A[_A][_Q]and A[_A][_Q][_z]==_AF:B.codeKey=A[_A][_h]['codeKey'];return{_B:0} if D[B]and D[B][T]and D[B][T][A9]==Ab:E.codeKey=D[B][m][BR];return{C:0}
return{_B:1,_e:E} return{C:1,i:H}
async def __verfiy_code(A,code): async def __verfiy_code(B,code):
C={_K:{_Z:'',_X:_t,_W:_M,_a:''},_y:{_n:A.phone,_Ag:'login',_H:code,'optSys':'ios','pushId':'00000','codeKey':A.codeKey},'Channels':'web'};B=await A.fetch(code_login_api,C);D=A.handle_request_result_message('code_login_api',B) E={M:{d:A,b:A3,a:O,e:A},A8:{u:B.phone,BQ:'login',J:code,'optSys':'ios','pushId':'00000',BR:B.codeKey},BP:AZ};D=await B.fetch(An,E);F=B.handle_request_result_message('code_login_api',D)
if _Q in B and _z in B[_Q]and B[_Q][_z]==_AF:A.token=B[_h][_l];A.userInfo=B[_h][_AC][0];return{_B:0} if T in D and A9 in D[T]and D[T][A9]==Ab:B.token=D[m][r];B.userInfo=D[m][AX][0];return{C:0}
return{_B:1,_e:D} return{C:1,i:F}
async def __get_request_authorize(B): async def __get_request_authorize(D):
A=await B.fetch(get_request_authorize_api,{});E=B.handle_request_result_message('get_request_authorize_api',A) A=await D.fetch(Ao,{});G=D.handle_request_result_message('get_request_authorize_api',A)
if _H in A and A[_H]==_F:C=A[_A][_Ae];D=C.rfind('code=');B.authorizeCode=C[D+5:D+5+32];return{_B:0} if J in A and A[J]==H:E=A[B][BN];F=E.rfind('code=');D.authorizeCode=E[F+5:F+5+32];return{C:0}
return{_B:1,_e:E} return{C:1,i:G}
async def __get_web_token(A): async def __get_web_token(A):
C={_H:A.authorizeCode};B=await A.fetch(get_web_token_api,C);D=A.handle_request_result_message('get_web_token_api',B) E={J:A.authorizeCode};D=await A.fetch(AO,E);F=A.handle_request_result_message('get_web_token_api',D)
if _H in B and B[_H]==_F:A.accessToken=B[_A][_Ah];A.refreshToken=B[_A][_AE];return{_B:0} if J in D and D[J]==H:A.accessToken=D[B][BS];A.refreshToken=D[B][Aa];return{C:0}
return{_B:1,_e:D} return{C:1,i:F}
async def __refresh_web_token(B): async def __refresh_web_token(D):
A=await B.fetch(refresh_web_token_api,{});C=B.handle_request_result_message('refresh_web_token_api',A) A=await D.fetch(Ap,{});E=D.handle_request_result_message('refresh_web_token_api',A)
if _H in A and A[_H]==_F:B.accessToken=A[_A][_Ah];B.refreshToken=A[_A][_AE];return{_B:0} if J in A and A[J]==H:D.accessToken=A[B][BS];D.refreshToken=A[B][Aa];return{C:0}
return{_B:1,_e:C} return{C:1,i:E}
async def __get_door_number(B): async def __get_door_number(E):
C={_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_A5][_K][_W],_Z:configuration[_A5][_K][_Z],_a:configuration[_A5][_K][_a],_X:configuration[_A5][_K][_X]},_y:{_R:B.userInfo[_R]},_l:B.token};A=await B.fetch(get_door_number_api,C);D=B.handle_request_result_message('get_door_number_api',A) H={D:F[D],G:F[G],V:F[V],M:{a:F[AE][M][a],d:F[AE][M][d],e:F[AE][M][e],b:F[AE][M][b]},A8:{U:E.userInfo[U]},r:E.token};A=await E.fetch(Aq,H);I=E.handle_request_result_message('get_door_number_api',A)
if _H in A and A[_H]==1 and _A in A and _h in A[_A]:B.powerUserList=A[_A][_h][_AP];return{_B:0} if J in A and A[J]==1 and B in A and m in A[B]:E.powerUserList=A[B][m][B0];return{C:0}
return{_B:1,_e:D} return{C:1,i:I}
async def __get_door_balance(C,door_account): async def __get_door_balance(L,door_account):
A=door_account;E={_A:{_L:'',_N:'',_G:configuration[_n][_G],_D:configuration[_n][_D],_A0:C.userInfo[_R],_A1:C.userInfo[_A9],_T:_F,_d:_F,_AG:C.userInfo[_R],_A2:[{_Ai:A[_m],_AA:A[_U],_Aj:A[_AQ],_i:A[_i],_Y:A[_Y]}]},_C:_AK,_E:configuration[_E],_S:A[_U]};B=await C.fetch(get_door_balance_api,E);C.handle_request_result_message('get_door_balance_api',B) C=door_account;O={B:{N:A,Q:A,I:F[u][I],E:F[u][E],AA:L.userInfo[U],AB:L.userInfo[AI],W:H,h:H,Ac:L.userInfo[U],AC:[{BT:C[s],AJ:C[X],BU:C[B1],n:C[n],c:C[c]}]},D:As,G:F[G],V:C[X]};K=await L.fetch(AP,O);L.handle_request_result_message('get_door_balance_api',K)
if _H in B and B[_H]==1 and _A in B and _A2 in B[_A]: if J in K and K[J]==1 and B in K and AC in K[B]:
D=B[_A][_A2] M=K[B][AC]
if len(D)!=0:A[_A3]=D[0] if t(M)!=0:C[AK]=M[0]
async def __get_door_bill(C,door_account,year): async def __get_door_bill(L,door_account,year):
F='dataInfo';D='mothEleList';A=door_account;E={_A:{_L:'',_N:'',_G:configuration[_n][_G],_D:configuration[_n][_D],_A0:C.userInfo[_R],_A1:C.userInfo[_A9],_T:_F,_d:_F,_AG:C.userInfo[_R],_A2:[{_Ai:A[_m],_AA:A[_U],_Aj:A['consSortCode'],_i:A[_i],_Y:A[_Y]}]},_C:_AK,_E:configuration[_E],_S:A[_U]};E={_A:{_A0:C.userInfo[_R],_G:configuration[_G],_g:'11',_AR:A[_AQ],_D:'ALIPAY_01',_Y:A[_Y],_AA:A[_U],_d:_F,_T:_F,_N:'',_L:'',_A1:'',_Ak:A[_U],_AG:C.userInfo[_R],_i:A[_i],_Al:year},_C:_x,_E:_w,_S:A[_U]};B=await C.fetch(get_door_bill_api,E);C.handle_request_result_message('get_door_bill_api',B) P='dataInfo';M='mothEleList';C=door_account;O={B:{N:A,Q:A,I:F[u][I],E:F[u][E],AA:L.userInfo[U],AB:L.userInfo[AI],W:H,h:H,Ac:L.userInfo[U],AC:[{BT:C[s],AJ:C[X],BU:C['consSortCode'],n:C[n],c:C[c]}]},D:As,G:F[G],V:C[X]};O={B:{AA:L.userInfo[U],I:F[I],l:'11',B2:C[B1],E:'ALIPAY_01',c:C[c],AJ:C[X],h:H,W:H,Q:A,N:A,AB:A,BV:C[X],Ac:L.userInfo[U],n:C[n],BW:year},D:A7,G:A6,V:C[X]};K=await L.fetch(AQ,O);L.handle_request_result_message('get_door_bill_api',K)
if _H in B and B[_H]==1 and _A in B: if J in K and K[J]==1 and B in K:
if F in B[_A]:A[_AH]=B[_A][F] if P in K[B]:C[Ad]=K[B][P]
if D in B[_A]:A[_A4]=B[_A][D];A[_AI]=B[_A][D][-1]['month'] if M in K[B]:C[AD]=K[B][M];C[Ae]=K[B][M][-1]['month']
async def __get_door_ladder(B,door_account,month): async def __get_door_ladder(H,door_account,month):
F='ladder_flag';E=month;A=door_account;G=A[_m];H={_A:{_G:configuration[_o][_G],_D:configuration[_o][_D],_T:configuration[_o][_T],_g:configuration[_o][_g],_i:A[_m],_d:A[_U],_Y:A[_Y],'queryDate':E,_Ak:A[_U],_AR:A[_AQ],_AG:B.userInfo[_R],_N:'',_L:'',_A1:B.userInfo[_A9],_A0:B.userInfo[_R]},_C:configuration[_o][_C],_E:configuration[_o][_E],_S:A[_U]};C=await B.fetch(get_door_ladder_api,H);I=B.handle_request_result_message('get_door_ladder_api',C) O='ladder_flag';M=month;C=door_account;P=C[s];R={B:{I:F[v][I],E:F[v][E],W:F[v][W],l:F[v][l],n:C[s],h:C[X],c:C[c],'queryDate':M,BV:C[X],B2:C[B1],Ac:H.userInfo[U],Q:A,N:A,AB:H.userInfo[AI],AA:H.userInfo[U]},D:F[v][D],G:F[v][G],V:C[X]};K=await H.fetch(AR,R);S=H.handle_request_result_message('get_door_ladder_api',K)
if _H in C and C[_H]==1 and _A in C and _A2 in C[_A]: if J in K and K[J]==1 and B in K and AC in K[B]:
D=C[_A][_A2] L=K[B][AC]
if len(D)!=0: if t(L)!=0:
D=D[0];D['month']=E L=L[0];L['month']=M
if D['electricParticulars']['levelFlag']=='2':A[F]=1 if L['electricParticulars']['levelFlag']=='2':C[O]=1
else:A[F]=0 else:C[O]=0
B.doorAccountDict[G]['ladder']=D H.doorAccountDict[P]['ladder']=L
async def __get_door_daily_bill(A,door_account,year,start_date,end_date): async def __get_door_daily_bill(C,door_account,year,start_date,end_date):
D='sevenEleList';C=door_account;E={'params1':{_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_K][_W],_Z:configuration[_K][_Z],_a:configuration[_K][_a],_X:configuration[_K][_X]},_y:{_R:A.userInfo[_R]},_l:A.token},'params3':{_A:{_A0:A.userInfo[_R],_i:C[_m],_AR:_c,'endTime':end_date,_Y:C[_Y],_Al:year,_AA:C[_U],_N:'',_L:'','startTime':start_date,_A1:A.userInfo[_A9],_D:configuration[_j][_D],_G:configuration[_j][_G],_g:configuration[_j][_g],_d:configuration[_j][_d],_T:configuration[_j][_T]},_C:configuration[_j][_C],_E:configuration[_j][_E],_S:C[_U]},'params4':'010103'};B=await A.fetch(get_door_daily_bill_api,E);F=A.handle_request_result_message('get_door_daily_bill_api',B) L='sevenEleList';K=door_account;O={BX:{D:F[D],G:F[G],V:F[V],M:{a:F[M][a],d:F[M][d],e:F[M][e],b:F[M][b]},A8:{U:C.userInfo[U]},r:C.token},BY:{B:{AA:C.userInfo[U],n:K[s],B2:g,'endTime':end_date,c:K[c],BW:year,AJ:K[X],Q:A,N:A,'startTime':start_date,AB:C.userInfo[AI],E:F[p][E],I:F[p][I],l:F[p][l],h:F[p][h],W:F[p][W]},D:F[p][D],G:F[p][G],V:K[X]},BZ:'010103'};H=await C.fetch(AT,O);P=C.handle_request_result_message('get_door_daily_bill_api',H)
if _H in B and B[_H]==1 and _A in B and D in B[_A]:C[_V]=B[_A][D] if J in H and H[J]==1 and B in H and L in H[B]:K[Y]=H[B][L]
async def __get_door_pay_record(A,door_account):B=door_account;D=B[_m];C={'params1':{_C:configuration[_C],_E:configuration[_E],_S:configuration[_S],_K:{_W:configuration[_K][_W],_Z:configuration[_K][_Z],_a:configuration[_K][_a],_X:configuration[_K][_X]},_y:{_R:A.userInfo[_R]},_l:A.token},'params3':{_A:{_A0:A.userInfo[_R],'bgnPayDate':'2023-04-24',_G:configuration[_G],_i:B[_m],'endPayDate':'2024-04-24',_D:'webALIPAY_01','number':100,_Y:B[_Y],'page':_F,_AA:B[_U],_d:_F,_T:_F,_N:'',_L:'',_A1:A.userInfo[_A9]},_C:'0101051',_E:_c,_S:B[_U]},'params4':'010104'};E=await A.fetch(getJiaoFeiRecordApi,C) async def __get_door_pay_record(C,door_account):J=door_account;L=J[s];K={BX:{D:F[D],G:F[G],V:F[V],M:{a:F[M][a],d:F[M][d],e:F[M][e],b:F[M][b]},A8:{U:C.userInfo[U]},r:C.token},BY:{B:{AA:C.userInfo[U],'bgnPayDate':'2023-04-24',I:F[I],n:J[s],'endPayDate':'2024-04-24',E:'webALIPAY_01','number':100,c:J[c],'page':H,AJ:J[X],h:H,W:H,Q:A,N:A,AB:C.userInfo[AI]},D:'0101051',G:g,V:J[X]},BZ:'010104'};O=await C.fetch(AS,K)
async def get_qr_code(B): async def get_qr_code(B):
A=await B.__get_request_key() A=await B.__get_request_key()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
return await B.__get_qr_code() return await B.__get_qr_code()
async def check_qr_code(B): async def check_qr_code(B):
A=await B.__get_qr_code_status() A=await B.__get_qr_code_status()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
A=await B.__get_qr_code_token() A=await B.__get_qr_code_token()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
return await B.__get_token() return await B.__get_token()
async def send_phone_code(B,phone): async def send_phone_code(B,phone):
A=await B.__get_request_key() A=await B.__get_request_key()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
return await B.__send_code(phone) return await B.__send_code(phone)
async def verfiy_phone_code(B,code): async def verfiy_phone_code(B,code):
A=await B.__verfiy_code(code) A=await B.__verfiy_code(code)
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
return await B.__get_token() return await B.__get_token()
async def __get_token(B): async def __get_token(D):
A=await B.__get_request_key() A=await D.__get_request_key()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
A=await B.__get_request_authorize() A=await D.__get_request_authorize()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
A=await B.__get_web_token() A=await D.__get_web_token()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
A=await B.__get_door_number() A=await D.__get_door_number()
if _B in A and A[_B]!=0:return A if C in A and A[C]!=0:return A
B.need_login=_s;await B.save_data();return{_B:0,_A:B.powerUserList} D.need_login=z;await D.save_data();return{C:0,B:D.powerUserList}
async def refresh_data(B,setup=_s): async def refresh_data(B,setup=z):
n='daily_t_ele_num';m='daily_n_ele_num';l='daily_v_ele_num';k='daily_p_ele_num';j='last_month_ele_cost';i='year_ele_cost';h='monthEleNum';g='thisTPq';f='thisNPq';e='thisVPq';d='thisPPq';U='daily_ele_num';T='last_month_ele_num';S='year_ele_num';R='ladder_level_num';Q='ladder_level';L='%Y%m%d';K='day';I='balance';H='dayElePq' q='daily_t_ele_num';p='daily_n_ele_num';o='daily_v_ele_num';n='daily_p_ele_num';m='daily_ele_num';l='last_month_ele_cost';k='last_month_ele_num';i='year_ele_cost';h='year_ele_num';g='monthEleNum';f='thisTPq';e='thisNPq';d='thisVPq';c='thisPPq';T='balance';S='ladder_level_num';R='ladder_level';L='%Y%m%d';K='day';I='dayElePq';r=setup or int(Af.time()*1000)-B.timestamp>B.refresh_interval*3600*1000
if B.need_login is True:LOGGER.error('国家电网需要重新登录!');return if r is z:return
o=setup or int(time.time()*1000)-B.timestamp>B.refresh_interval*3600*1000 E=await B.__get_door_number()
if o is _s:return if C in E and E[C]!=0:
D=await B.__get_door_number() A0.warning('刷新 Token');E=await B.__get_request_key()
if _B in D and D[_B]!=0: if C in E and E[C]!=0:return
LOGGER.warning('刷新 Token');D=await B.__get_request_key() E=await B.__refresh_web_token()
if _B in D and D[_B]!=0:return if C in E and E[C]==0:await B.save_data()
D=await B.__refresh_web_token() else:B.need_login=AW;A0.error('刷新 Token 失败');return
if _B in D and D[_B]==0:await B.save_data() E=await B.__get_door_number()
else:B.need_login=True;LOGGER.error('刷新 Token 失败');return if C in E and E[C]!=0:B.need_login=AW;A0.error('重新请求失败');return
D=await B.__get_door_number() M=j.datetime.now();J=M-j.timedelta(days=1);u=f"{J.year}-{J.month:02d}-{J.day:02d}";N=J-j.timedelta(days=40);v=f"{N.year}-{N.month:02d}-{N.day:02d}"
if _B in D and D[_B]!=0:B.need_login=True;LOGGER.error('重新请求失败');return
M=datetime.datetime.now();J=M-datetime.timedelta(days=1);p=f"{J.year}-{J.month:02d}-{J.day:02d}";N=J-datetime.timedelta(days=40);q=f"{N.year}-{N.month:02d}-{N.day:02d}"
for A in B.powerUserList: for A in B.powerUserList:
r=A[_m];B.doorAccountDict[r]=A;await B.__get_door_balance(A);await B.__get_door_daily_bill(A,M.year,q,p);O=A[_V][0] w=A[s];B.doorAccountDict[w]=A;await B.__get_door_balance(A);await B.__get_door_daily_bill(A,M.year,v,u);O=A[Y][0]
try:float(O[H]) try:float(O[I])
except:A[_V].pop(0) except:A[Y].pop(0)
O=A[_V][0];E=datetime.datetime.strptime(O[K],L);V=0;W=0;X=0;Y=0;Z=0 O=A[Y][0];F=j.datetime.strptime(O[K],L);U=0;V=0;W=0;X=0;Z=0
for C in A[_V]: for D in A[Y]:
G=datetime.datetime.strptime(C[K],L) H=j.datetime.strptime(D[K],L)
if G.month!=E.month:break if H.month!=F.month:break
V+=catchFloat(C,H);W+=catchFloat(C,d);X+=catchFloat(C,e);Y+=catchFloat(C,f);Z+=catchFloat(C,g) U+=P(D,I);V+=P(D,c);W+=P(D,d);X+=P(D,e);Z+=P(D,f)
P=E-datetime.timedelta(days=E.day);a=f"{P.year}-{P.month:02d}" Q=F-j.timedelta(days=F.day);a=f"{Q.year}-{Q.month:02d}"
if _AI not in A or A[_AI]!=a:await B.__get_door_bill(A,P.year);await B.__get_door_ladder(A,a) if Ae not in A or A[Ae]!=a:await B.__get_door_bill(A,Q.year);await B.__get_door_ladder(A,a)
s=datetime.datetime.strptime(A[_AI],'%Y%m') x=j.datetime.strptime(A[Ae],'%Y%m')
if s.month==12: if x.month==12:
F=0 G=0
for C in A[_V]: for D in A[Y]:
G=datetime.datetime.strptime(C[K],L) H=j.datetime.strptime(D[K],L)
if G.month!=12:break if H.month!=12:break
F+=catchFloat(C,H) G+=P(D,I)
else: else:
F=0 G=0
for C in A[_A4]:F+=catchFloat(C,h) for D in A[AD]:G+=P(D,g)
t=len(A[_A4]) y=t(A[AD])
for C in A[_V]: for D in A[Y]:
G=datetime.datetime.strptime(C[K],L) H=j.datetime.strptime(D[K],L)
if G.month<=t:break if H.month<=y:break
F+=catchFloat(C,H) G+=P(D,I)
if F<=2760:A[Q]='第一阶梯';A[R]=1 if G<=2760:A[R]='第一阶梯';A[S]=1
elif F<=4800:A[Q]='第二阶梯';A[R]=2 elif G<=4800:A[R]='第二阶梯';A[S]=2
else:A[Q]='第三阶梯';A[R]=3 else:A[R]='第三阶梯';A[S]=3
if _A3 in A: if AK in A:
u=catchFloat(A[_A3],'estiAmt');b=catchFloat(A[_A3],'prepayBal');v=catchFloat(A[_A3],'sumMoney') A1=P(A[AK],'estiAmt');A2=P(A[AK],'prepayBal');A[T]=A2-A1;b=P(A[AK],'historyOwe')
if b==0:A[I]=v if b>0:A[T]=-b
else:A[I]=b-u else:A[T]=0
c=catchFloat(A[_A3],'historyOwe') if Ad in A:A[h]=P(A[Ad],'totalEleNum');A[i]=P(A[Ad],'totalEleCost')
if c>0:A[I]=-c else:A[h]=0;A[i]=0
elif I not in A:A[I]=0 if AD in A:A[k]=P(A[AD][-1],g);A[l]=P(A[AD][-1],'monthEleCost')
if _AH in A:A[S]=catchFloat(A[_AH],'totalEleNum');A[i]=catchFloat(A[_AH],'totalEleCost') else:A[k]=0;A[l]=0
elif S not in A:A[S]=0;A[i]=0 if Y in A:A[m]=P(A[Y][0],I);A[n]=P(A[Y][0],c);A[o]=P(A[Y][0],d);A[p]=P(A[Y][0],e);A[q]=P(A[Y][0],f)
if _A4 in A:A[T]=catchFloat(A[_A4][-1],h);A[j]=catchFloat(A[_A4][-1],'monthEleCost') else:A[m]=0;A[n]=0;A[o]=0;A[p]=0;A[q]=0
elif T not in A:A[T]=0;A[j]=0 A['month_ele_num']=U;A['month_p_ele_num']=V;A['month_v_ele_num']=W;A['month_n_ele_num']=X;A['month_t_ele_num']=Z;A['daily_lasted_date']=f"{F.year}-{F.month:02d}-{F.day:02d}";A['refresh_time']=j.datetime.strftime(M,'%Y-%m-%d %H:%M:%S')
if _V in A:A[U]=catchFloat(A[_V][0],H);A[k]=catchFloat(A[_V][0],d);A[l]=catchFloat(A[_V][0],e);A[m]=catchFloat(A[_V][0],f);A[n]=catchFloat(A[_V][0],g)
elif U not in A:A[U]=0;A[k]=0;A[l]=0;A[m]=0;A[n]=0
A['month_ele_num']=V;A['month_p_ele_num']=W;A['month_v_ele_num']=X;A['month_n_ele_num']=Y;A['month_t_ele_num']=Z;A['daily_lasted_date']=f"{E.year}-{E.month:02d}-{E.day:02d}";A['refresh_time']=datetime.datetime.strftime(M,'%Y-%m-%d %H:%M:%S')
await B.save_data() await B.save_data()
async def get_door_account_list(A):return list(A.doorAccountDict.values()) async def get_door_account_list(A):return list(A.doorAccountDict.values())
def get_door_account(A):return A.doorAccountDict def get_door_account(A):return A.doorAccountDict
+1 -1
View File
@@ -5,5 +5,5 @@
"config_flow": true, "config_flow": true,
"documentation": "https://github.com/hass-box/state-grid", "documentation": "https://github.com/hass-box/state-grid",
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"version": "0.0.6" "version": "0.0.4"
} }
+135 -141
View File
@@ -2,11 +2,13 @@ from homeassistant.components.sensor import (
DOMAIN as SENSOR_DOMAIN, DOMAIN as SENSOR_DOMAIN,
SensorDeviceClass, SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription,
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfEnergy from homeassistant.const import UnitOfEnergy
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
@@ -20,128 +22,128 @@ CURRENCY_YUAN = "元"
ENTITY_ID_SENSOR_FORMAT = SENSOR_DOMAIN + ".state_grid_" ENTITY_ID_SENSOR_FORMAT = SENSOR_DOMAIN + ".state_grid_"
SENSOR_TYPES = [ SENSOR_TYPES = (
{ SensorEntityDescription(
"key":"balance", key="balance",
"name": "账户余额", translation_key="balance",
"native_unit_of_measurement": CURRENCY_YUAN, native_unit_of_measurement=CURRENCY_YUAN,
"device_class": SensorDeviceClass.MONETARY, device_class=SensorDeviceClass.MONETARY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "year_ele_num", key="year_ele_num",
"name": "年度累计用电", translation_key="year_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "year_ele_cost", key="year_ele_cost",
"name": "年度累计电费", translation_key="year_ele_cost",
"native_unit_of_measurement": CURRENCY_YUAN, native_unit_of_measurement=CURRENCY_YUAN,
"device_class": SensorDeviceClass.MONETARY, device_class=SensorDeviceClass.MONETARY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "last_month_ele_num", key="last_month_ele_num",
"name": "上个月用电", translation_key="last_month_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "last_month_ele_cost", key="last_month_ele_cost",
"name": "上个月电费", translation_key="last_month_ele_cost",
"native_unit_of_measurement": CURRENCY_YUAN, native_unit_of_measurement=CURRENCY_YUAN,
"device_class": SensorDeviceClass.MONETARY, device_class=SensorDeviceClass.MONETARY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "month_ele_num", key="month_ele_num",
"name": "当月累计用电", translation_key="month_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "month_p_ele_num", key="month_p_ele_num",
"name": "当月累计峰用电", translation_key="month_p_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "month_v_ele_num", key="month_v_ele_num",
"name": "当月累计谷用电", translation_key="month_v_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "month_n_ele_num", key="month_n_ele_num",
"name": "当月累计平用电", translation_key="month_n_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "month_t_ele_num", key="month_t_ele_num",
"name": "当月累计尖用电", translation_key="month_t_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "daily_ele_num", key="daily_ele_num",
"name": "日总用电", translation_key="daily_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "daily_p_ele_num", key="daily_p_ele_num",
"name": "日峰用电", translation_key="daily_p_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "daily_v_ele_num", key="daily_v_ele_num",
"name": "日谷用电", translation_key="daily_v_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "daily_n_ele_num", key="daily_n_ele_num",
"name": "日平用电", translation_key="daily_n_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "daily_t_ele_num", key="daily_t_ele_num",
"name": "日尖用电", translation_key="daily_t_ele_num",
"native_unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
"device_class": SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
"state_class": SensorStateClass.TOTAL state_class=SensorStateClass.TOTAL
}, ),
{ SensorEntityDescription(
"key": "daily_lasted_date", key="daily_lasted_date",
"name": "最新日用电日期" translation_key="daily_lasted_date"
}, ),
{ SensorEntityDescription(
"key": "refresh_time", key="refresh_time",
"name": "最近刷新时间" translation_key="refresh_time"
} )
] )
SENSOR_TYPES_FOR_LADDER = [ SENSOR_TYPES_FOR_LADDER = (
{ SensorEntityDescription(
"key": "ladder_level", key="ladder_level",
"name": "当前阶梯" translation_key="ladder_level"
}, ),
] )
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
@@ -152,47 +154,39 @@ async def async_setup_entry(
door_account_list = await data_client.get_door_account_list() door_account_list = await data_client.get_door_account_list()
for door_account in door_account_list: for door_account in door_account_list:
async_add_entities( async_add_entities(
[StateGridSensor(door_account, sensor_type, entry.entry_id, coordinator) for sensor_type in SENSOR_TYPES] [StateGridSensor(door_account, description, entry.entry_id, coordinator) for description in SENSOR_TYPES]
) )
# if door_account["ladder_flag"] == 1: # if door_account["ladder_flag"] == 1:
# async_add_entities( # async_add_entities(
# StateGridSensor(door_account, sensor_type, entry.entry_id) # StateGridSensor(door_account, description, entry.entry_id)
# for sensor_type in SENSOR_TYPES_FOR_LADDER # for description in SENSOR_TYPES_FOR_LADDER
# ) # )
class StateGridSensor(CoordinatorEntity[StateGridCoordinator], SensorEntity): class StateGridSensor(CoordinatorEntity[StateGridCoordinator], SensorEntity):
_attr_has_entity_name = True _attr_has_entity_name = True
entity_description: SensorEntityDescription
def __init__( def __init__(
self, door_account, sensor_type, entry_id: str, coordinator: StateGridCoordinator, self, door_account, entity_description: SensorEntityDescription, entry_id: str, coordinator: StateGridCoordinator,
) -> None: ) -> None:
super().__init__(coordinator) super().__init__(coordinator)
self.entity_description = entity_description
self.door_account = door_account self.door_account = door_account
self.sensor_type = sensor_type self.entity_id = SENSOR_DOMAIN + ".state_grid" + "_" + door_account["consNo_dst"] + "_" + entity_description.key
self.entity_id = SENSOR_DOMAIN + ".state_grid" + "_" + door_account["consNo_dst"] + "_" + sensor_type["key"] self._attr_translation_key = entity_description.key
self._attr_name = sensor_type["name"] self._attr_unique_id = entry_id + "-" + door_account["consNo_dst"] + "-" + entity_description.key
self._attr_unique_id = entry_id + "-" + door_account["consNo_dst"] + "-" + sensor_type["key"]
if "device_class" in sensor_type:
self._attr_device_class = sensor_type["device_class"]
if "state_class" in sensor_type:
self._attr_state_class = sensor_type["state_class"]
if "native_unit_of_measurement" in sensor_type:
self._attr_native_unit_of_measurement = sensor_type["native_unit_of_measurement"]
self._attr_device_info = { self._attr_device_info = {
"name": door_account["elecAddr_dst"], "name": door_account["elecAddr_dst"],
"identifiers": {(DOMAIN, door_account["consNo_dst"])}, "identifiers": {(DOMAIN, door_account["consNo_dst"])},
"sw_version": VERSION, "sw_version": VERSION,
"manufacturer": "HassBox", "manufacturer": "HassBox",
"model": "户号:" + door_account["consName_dst"] + " - " + door_account["consNo_dst"] "model": "户号:" + door_account["consName_dst"] + " - " + door_account["consNo_dst"],
"entry_type": DeviceEntryType.SERVICE,
} }
@property @property
def native_value(self): def native_value(self):
data = self.coordinator.data[self.door_account["consNo_dst"]] data = self.coordinator.data[self.door_account["consNo_dst"]]
return data[self.sensor_type["key"]] return data[self.entity_description.key]
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB