Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c26474e7b3 |
Vendored
BIN
Binary file not shown.
@@ -1,4 +1,4 @@
|
|||||||
DOMAIN = "state_grid"
|
DOMAIN = "state_grid"
|
||||||
PACKAGE_NAME = "custom_components.state_grid"
|
PACKAGE_NAME = "custom_components.state_grid"
|
||||||
VERSION = "0.1.8"
|
VERSION = "0.1.7"
|
||||||
VERSION_STORAGE = 1
|
VERSION_STORAGE = 1
|
||||||
|
|||||||
@@ -270,25 +270,22 @@ class StateGridDataClient:
|
|||||||
if _H in B and B[_H]==1 and _A in B and _u in B[_A]:
|
if _H in B and B[_H]==1 and _A in B and _u in B[_A]:
|
||||||
D=B[_A][_u]
|
D=B[_A][_u]
|
||||||
if len(D)!=0:D=D[0];E['ladder']=D
|
if len(D)!=0:D=D[0];E['ladder']=D
|
||||||
async def __get_door_mouth_bill(I,door_account,monthBill):
|
async def __get_door_mouth_bill(F,door_account,monthBill):
|
||||||
S=monthBill;O='quantity';N='priceName';K='amtGroupList';H='readList';E=door_account;C='amtList';B='pointList';T=datetime.datetime.strptime(S[_AN],'%Y%m');V=f"{T.year}-{T.month:02d}";W={_A:{_I:configuration[_V][_I],_D:configuration[_V][_D],_T:configuration[_V][_T],_e:configuration[_V][_e],_q:E[_g],_d:E[_U],_Y:E[_Y],_Av:V,_AV:E[_U],_AL:E[_AW],_AI:I.userInfo[_R],_N:'',_L:'',_A4:I.userInfo[_AB],_A3:I.userInfo[_R]},_C:configuration[_V][_C],_E:configuration[_V][_E],_S:E[_U]};F=await I.__fetch(get_door_ladder_api,W);X=I.handle_request_result_message(_Aw,F)
|
S='pointList';K=monthBill;J='amtList';I='readList';H='quantity';G='priceName';B=door_account;L=datetime.datetime.strptime(K[_AN],'%Y%m');T=f"{L.year}-{L.month:02d}";U={_A:{_I:configuration[_V][_I],_D:configuration[_V][_D],_T:configuration[_V][_T],_e:configuration[_V][_e],_q:B[_g],_d:B[_U],_Y:B[_Y],_Av:T,_AV:B[_U],_AL:B[_AW],_AI:F.userInfo[_R],_N:'',_L:'',_A4:F.userInfo[_AB],_A3:F.userInfo[_R]},_C:configuration[_V][_C],_E:configuration[_V][_E],_S:B[_U]};C=await F.__fetch(get_door_ladder_api,U);W=F.handle_request_result_message(_Aw,C)
|
||||||
if _H in F and F[_H]==1 and _A in F and _u in F[_A]:
|
if _H in C and C[_H]==1 and _A in C and _u in C[_A]:
|
||||||
A=F[_A][_u][0];U=0;P=0;Q=0;L=0;R=0;M=[]
|
D=C[_A][_u][0]
|
||||||
if H in A and len(A[H])>0:M=A[H]
|
if I in D:M=D[I][0]
|
||||||
elif B in A and len(A[B])>0 and H in A[B][0]and len(A[B][0][H])>0:M=A[B][0][H]
|
else:M=D[S][0][I][0]
|
||||||
if len(M)>0:U=catchFloat(M[0],'activeCount')
|
V=catchFloat(M,'activeCount')
|
||||||
J=[]
|
if J in D:N=D[J]
|
||||||
if C in A and len(A[C])>0:J=A[C]
|
else:N=D[S][0]['amtGroupList'][0][J]
|
||||||
elif B in A and len(A[B])>0 and C in A[B][0]and len(A[B][0][C])>0:J=A[B][0][C]
|
O=0;P=0;Q=0;R=0
|
||||||
elif B in A and len(A[B])>0 and K in A[B][0]and len(A[B][0][K])>0 and C in A[B][0][K][0]and len(A[B][0][K][0][C])>0:J=A[B][0][K][0][C]
|
for A in N:
|
||||||
if len(J)>0:
|
if A[G]=='峰':O=catchFloat(A,H)
|
||||||
for D in J:
|
elif A[G]=='谷':P=catchFloat(A,H)
|
||||||
if D[N]=='峰':P=catchFloat(D,O)
|
elif A[G]=='平':Q=catchFloat(A,H)
|
||||||
elif D[N]=='谷':Q=catchFloat(D,O)
|
elif A[G]=='尖':R=catchFloat(A,H)
|
||||||
elif D[N]=='平':L=catchFloat(D,O)
|
E={};E[_AX]=normal_round(V,2);E[_AY]=normal_round(O,2);E[_AZ]=normal_round(P,2);E[_Aa]=normal_round(Q,2);E[_Ab]=normal_round(R,2);K[_h]=E
|
||||||
elif D[N]=='尖':R=catchFloat(D,O)
|
|
||||||
if L==0:L=P+Q+R
|
|
||||||
G={};G[_AX]=normal_round(U,2);G[_AY]=normal_round(P,2);G[_AZ]=normal_round(Q,2);G[_Aa]=normal_round(L,2);G[_Ab]=normal_round(R,2);S[_h]=G
|
|
||||||
async def __get_door_daily_bill(B,door_account,year,start_date,end_date):
|
async def __get_door_daily_bill(B,door_account,year,start_date,end_date):
|
||||||
D='sevenEleList';A=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]},_A1:{_R:B.userInfo[_R]},_p:B.token},'params3':{_A:{_A3:B.userInfo[_R],_q:A[_g],_AL:_c,'endTime':end_date,_Y:A[_Y],_Au:year,_AJ:A.get(_U,A.get(_AK,_F)),_N:'',_L:'','startTime':start_date,_A4:B.userInfo[_AB],_D:configuration[_m][_D],_I:configuration[_m][_I],_e:configuration[_m][_e],_d:configuration[_m][_d],_T:configuration[_m][_T]},_C:configuration[_m][_C],_E:configuration[_m][_E],_S:A.get(_U,A.get(_AK,_F))},'params4':'010103'};C=await B.__fetch_safe(get_door_daily_bill_api,E);F=B.handle_request_result_message('get_door_daily_bill_api',C)
|
D='sevenEleList';A=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]},_A1:{_R:B.userInfo[_R]},_p:B.token},'params3':{_A:{_A3:B.userInfo[_R],_q:A[_g],_AL:_c,'endTime':end_date,_Y:A[_Y],_Au:year,_AJ:A.get(_U,A.get(_AK,_F)),_N:'',_L:'','startTime':start_date,_A4:B.userInfo[_AB],_D:configuration[_m][_D],_I:configuration[_m][_I],_e:configuration[_m][_e],_d:configuration[_m][_d],_T:configuration[_m][_T]},_C:configuration[_m][_C],_E:configuration[_m][_E],_S:A.get(_U,A.get(_AK,_F))},'params4':'010103'};C=await B.__fetch_safe(get_door_daily_bill_api,E);F=B.handle_request_result_message('get_door_daily_bill_api',C)
|
||||||
if _H in C and C[_H]==1 and _A in C and D in C[_A]:A[_A6]=C[_A][D]
|
if _H in C and C[_H]==1 and _A in C and D in C[_A]:A[_A6]=C[_A][D]
|
||||||
@@ -329,67 +326,65 @@ class StateGridDataClient:
|
|||||||
elif A.retry_times>=3:A.need_login=_o
|
elif A.retry_times>=3:A.need_login=_o
|
||||||
else:A.retry_times=A.retry_times+1
|
else:A.retry_times=A.retry_times+1
|
||||||
async def refresh_data(B,setup=_i,force_refresh=_i):
|
async def refresh_data(B,setup=_i,force_refresh=_i):
|
||||||
t='last_month_ele_cost';s='year_ele_cost';r='thisTPq';q='thisNPq';p='thisVPq';o='thisPPq';n='%Y%m%d';m='day';l='refresh_time';e=setup;d='last_month_ele_num';c='dayElePq';U='year_ele_num';K='balance'
|
t='last_month_ele_cost';s='year_ele_cost';r='thisTPq';q='thisNPq';p='thisVPq';o='thisPPq';n='%Y%m%d';m='day';l='refresh_time';a=setup;Z='last_month_ele_num';Y='dayElePq';T='year_ele_num';G='balance'
|
||||||
if e is _o:
|
if a is _o:
|
||||||
if B.dataVersion!=VERSION:B.powerUserList=_F
|
if B.dataVersion!=VERSION:B.powerUserList=_F
|
||||||
f=await B.__get_door_number()
|
b=await B.__get_door_number()
|
||||||
if _B in f and f[_B]!=0:B.need_login=_o
|
if _B in b and b[_B]!=0:B.need_login=_o
|
||||||
if B.need_login is _o:
|
if B.need_login is _o:
|
||||||
if B.powerUserList is not _F:
|
if B.powerUserList is not _F:
|
||||||
for A in B.get_door_account_list():A[l]='Token刷新失败,请重新登录'
|
for A in B.get_door_account_list():A[l]='Token刷新失败,请重新登录'
|
||||||
LOGGER.error('国家电网 - Token刷新失败,请重新登录!');return
|
LOGGER.error('国家电网 - Token刷新失败,请重新登录!');return
|
||||||
u=e or force_refresh or int(time.time()*1000)-B.timestamp>B.refresh_interval*3600*1000
|
u=a or force_refresh or int(time.time()*1000)-B.timestamp>B.refresh_interval*3600*1000
|
||||||
if u is _i:return
|
if u is _i:return
|
||||||
V=datetime.datetime.now();G=V-datetime.timedelta(days=1);v=f"{G.year}-{G.month:02d}-{G.day:02d}";W=G-datetime.timedelta(days=40);w=f"{W.year}-{W.month:02d}-{W.day:02d}"
|
U=datetime.datetime.now();F=U-datetime.timedelta(days=1);v=f"{F.year}-{F.month:02d}-{F.day:02d}";V=F-datetime.timedelta(days=40);w=f"{V.year}-{V.month:02d}-{V.day:02d}"
|
||||||
for A in B.powerUserList:
|
for A in B.powerUserList:
|
||||||
x=A[_g];B.doorAccountDict[x]=A;await B.__get_door_balance(A)
|
x=A[_g];B.doorAccountDict[x]=A;await B.__get_door_balance(A)
|
||||||
if B.retry_times!=0:return
|
if B.retry_times!=0:return
|
||||||
if _A5 in A:
|
if _A5 in A:
|
||||||
y=catchFloat(A[_A5],'estiAmt');X=catchFloat(A[_A5],'prepayBal');g=catchFloat(A[_A5],'sumMoney')
|
y=catchFloat(A[_A5],'estiAmt');W=catchFloat(A[_A5],'prepayBal');c=catchFloat(A[_A5],'sumMoney')
|
||||||
if X==0 or X==g:A[K]=g
|
if W==0 or W==c:A[G]=c
|
||||||
else:A[K]=X-y
|
else:A[G]=W-y
|
||||||
h=catchFloat(A[_A5],'historyOwe')
|
d=catchFloat(A[_A5],'historyOwe')
|
||||||
if h>0:A[K]=-h
|
if d>0:A[G]=-d
|
||||||
else:LOGGER.error('国家电网账户余额获取失败!')
|
else:LOGGER.error('国家电网账户余额获取失败!')
|
||||||
if K not in A:A[K]=0
|
if G not in A:A[G]=0
|
||||||
await B.__get_door_daily_bill(A,V.year,w,v)
|
await B.__get_door_daily_bill(A,U.year,w,v)
|
||||||
if _A6 not in A:LOGGER.error('国家电网无法获取日用电数据!');continue
|
if _A6 not in A:LOGGER.error('国家电网无法获取日用电数据!');continue
|
||||||
Y=0;L=_i
|
X=0;H=_i
|
||||||
for i in range(10):
|
for e in range(10):
|
||||||
D=A[_A6][i]
|
D=A[_A6][e]
|
||||||
try:float(D[c]);L=_o;break
|
try:float(D[Y]);H=_o;break
|
||||||
except:Y=Y+1
|
except:X=X+1
|
||||||
j=0;Z=0;a=0;M=0;b=0
|
f=0;g=0;h=0;i=0;j=0
|
||||||
if L:
|
if H:
|
||||||
for i in range(Y):A[_A6].pop(0)
|
for e in range(X):A[_A6].pop(0)
|
||||||
D=A[_A6][0];E=datetime.datetime.strptime(D[m],n);A['daily_lasted_date']=f"{E.year}-{E.month:02d}-{E.day:02d}";j=catchFloat(D,c);Z=catchFloat(D,o);a=catchFloat(D,p);M=catchFloat(D,q);b=catchFloat(D,r)
|
D=A[_A6][0];E=datetime.datetime.strptime(D[m],n);A['daily_lasted_date']=f"{E.year}-{E.month:02d}-{E.day:02d}";f=catchFloat(D,Y);g=catchFloat(D,o);h=catchFloat(D,p);i=catchFloat(D,q);j=catchFloat(D,r)
|
||||||
if M==0:M=Z+a+b
|
A['daily_ele_num']=normal_round(f,2);A['daily_p_ele_num']=normal_round(g,2);A['daily_v_ele_num']=normal_round(h,2);A['daily_n_ele_num']=normal_round(i,2);A['daily_t_ele_num']=normal_round(j,2);I=0;J=0;K=0;L=0;M=0
|
||||||
A['daily_ele_num']=normal_round(j,2);A['daily_p_ele_num']=normal_round(Z,2);A['daily_v_ele_num']=normal_round(a,2);A['daily_n_ele_num']=normal_round(M,2);A['daily_t_ele_num']=normal_round(b,2);N=0;H=0;I=0;F=0;J=0
|
if H:
|
||||||
if L:
|
|
||||||
for C in A[_A6]:
|
for C in A[_A6]:
|
||||||
z=datetime.datetime.strptime(C[m],n)
|
z=datetime.datetime.strptime(C[m],n)
|
||||||
if z.month!=E.month:break
|
if z.month!=E.month:break
|
||||||
N+=catchFloat(C,c);H+=catchFloat(C,o);I+=catchFloat(C,p);F+=catchFloat(C,q);J+=catchFloat(C,r)
|
I+=catchFloat(C,Y);J+=catchFloat(C,o);K+=catchFloat(C,p);L+=catchFloat(C,q);M+=catchFloat(C,r)
|
||||||
if F==0:F=H+I+J
|
A[_AX]=normal_round(I,2);A[_AY]=normal_round(J,2);A[_AZ]=normal_round(K,2);A[_Aa]=normal_round(L,2);A[_Ab]=normal_round(M,2)
|
||||||
A[_AX]=normal_round(N,2);A[_AY]=normal_round(H,2);A[_AZ]=normal_round(I,2);A[_Aa]=normal_round(F,2);A[_Ab]=normal_round(J,2)
|
if H:
|
||||||
if L:
|
N=E-datetime.timedelta(days=E.day);A0=f"{N.year}{N.month:02d}"
|
||||||
O=E-datetime.timedelta(days=E.day);A0=f"{O.year}{O.month:02d}"
|
if _AC not in A or A[_AC]!=N.year or _v not in A or A[_v][_AN]!=A0:await B.__get_door_bill(A,N)
|
||||||
if _AC not in A or A[_AC]!=O.year or _v not in A or A[_v][_AN]!=A0:await B.__get_door_bill(A,O)
|
|
||||||
if _l in A:
|
if _l in A:
|
||||||
for C in A[_l]:
|
for C in A[_l]:
|
||||||
if _h not in C:await B.__get_door_mouth_bill(A,C)
|
if _h not in C:await B.__get_door_mouth_bill(A,C)
|
||||||
if _AM in A:A[U]=catchFloat(A[_AM],'totalEleNum');A[s]=catchFloat(A[_AM],'totalEleCost')
|
if _AM in A:A[T]=catchFloat(A[_AM],'totalEleNum');A[s]=catchFloat(A[_AM],'totalEleCost')
|
||||||
if U not in A:A[U]=0;A[s]=0
|
if T not in A:A[T]=0;A[s]=0
|
||||||
if _v in A:A[d]=catchFloat(A[_v],'monthEleNum');A[t]=catchFloat(A[_v],'monthEleCost');k=datetime.datetime.strptime(A[_v][_AN],'%Y%m')
|
if _v in A:A[Z]=catchFloat(A[_v],'monthEleNum');A[t]=catchFloat(A[_v],'monthEleCost');k=datetime.datetime.strptime(A[_v][_AN],'%Y%m')
|
||||||
if d not in A:A[d]=0;A[t]=0;k=G.month
|
if Z not in A:A[Z]=0;A[t]=0;k=F.month
|
||||||
P=0;Q=0;R=0;S=0;T=0
|
O=0;P=0;Q=0;R=0;S=0
|
||||||
if k.month==12:P=N;Q=H;R=I;S=F;T=J
|
if k.month==12:O=I;P=J;Q=K;R=L;S=M
|
||||||
else:
|
else:
|
||||||
if _l in A:
|
if _l in A:
|
||||||
for C in A[_l]:
|
for C in A[_l]:
|
||||||
if _h in C:P+=C[_h][_AX];Q+=C[_h][_AY];R+=C[_h][_AZ];S+=C[_h][_Aa];T+=C[_h][_Ab]
|
if _h in C:O+=C[_h][_AX];P+=C[_h][_AY];Q+=C[_h][_AZ];R+=C[_h][_Aa];S+=C[_h][_Ab]
|
||||||
P+=N;Q+=H;R+=I;S+=F;T+=J
|
O+=I;P+=J;Q+=K;R+=L;S+=M
|
||||||
A[U]=normal_round(P,2);A['year_p_ele_num']=normal_round(Q,2);A['year_v_ele_num']=normal_round(R,2);A['year_n_ele_num']=normal_round(S,2);A['year_t_ele_num']=normal_round(T,2);A[l]=datetime.datetime.strftime(V,'%Y-%m-%d %H:%M:%S')
|
A[T]=normal_round(O,2);A['year_p_ele_num']=normal_round(P,2);A['year_v_ele_num']=normal_round(Q,2);A['year_n_ele_num']=normal_round(R,2);A['year_t_ele_num']=normal_round(S,2);A[l]=datetime.datetime.strftime(U,'%Y-%m-%d %H:%M:%S')
|
||||||
await B.save_data()
|
await B.save_data()
|
||||||
def get_door_account_list(A):return list(A.doorAccountDict.values())
|
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
|
||||||
@@ -5,5 +5,5 @@
|
|||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://hassbox.cn/",
|
"documentation": "https://hassbox.cn/",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"version": "0.1.8"
|
"version": "0.1.7"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user