Skip to content

Commit

Permalink
support "peak"/"ground"/"valley" type and fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
georgezhao2010 authored Sep 4, 2021
1 parent 9f722ed commit afb4f62
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
12 changes: 6 additions & 6 deletions custom_components/bj_sgcc_energy/const.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
DOMAIN = "bj_sgcc_energy"

PGC_PRICE = {
"climax": {
PGC_PRICE = [
{
"key": "尖峰",
"month": [7, 8],
"time_slot": [[11, 13], [16, 17]]
},
"peak": {
{
"key": "峰",
"time_slot": [[10, 15], [18, 21]]
},
"ground": {
{
"key": "平",
"time_slot": [[7, 10], [15, 18], [21, 23]]
},
"valley": {
{
"key": "谷",
"time_slot": [[23, 7]]
}
}
]
4 changes: 4 additions & 0 deletions custom_components/bj_sgcc_energy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"name": "本年度电费",
"icon": "hass:cash-100",
"unit_of_measurement": "元"
},
"current_pgv_type": {
"name": "当前电价类别",
"icon": "hass:cash-100"
}
}

Expand Down
10 changes: 5 additions & 5 deletions custom_components/bj_sgcc_energy/sgcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
LEVEL_REMAIN = ["levelOneRemain", "levelTwoRemain"]


def get_price_key():
def get_pgv_type():
dt = datetime.datetime.now()
for pgc_price in PGC_PRICE.values():
for pgc_price in PGC_PRICE:
# month is none or month matched
if pgc_price.get("moon") is None or pgc_price.get("moon")[0] <= dt.month <= pgc_price.get("moon")[1]:
slot_len = len(pgc_price.get("time_slot"))
Expand All @@ -28,7 +28,7 @@ def get_price_key():
(pgc_price.get("time_slot")[n][0] <= dt.hour or pgc_price.get("time_slot")[n][
1] > dt.hour)):
return pgc_price.get("key")
return None
return "Unknown"


class SGCCData:
Expand Down Expand Up @@ -159,9 +159,9 @@ def getDetail(self, consNo):
key = LEVEL_REMAIN[self._info[consNo]["current_level"] - 1]
self._info[consNo]["current_level_remain"] = int(data[key])
elif bill_size >= 3:
price_key = get_price_key()
pgv_type = get_pgv_type()
for n in range(0, bill_size):
if data["billDetails"][n]["PRC_TS_NAME"] == price_key:
if data["billDetails"][n]["PRC_TS_NAME"] == pgv_type:
self._info[consNo]["current_price"] = data["billDetails"][n]["KWH_PRC"]
break;
self._info[consNo]["year_consume"] = data["TOTAL_ELEC"]
Expand Down

0 comments on commit afb4f62

Please sign in to comment.