Skip to content

Commit efeb012

Browse files
authored
Merge pull request #327 from claudegel/energy
fix broken Energy stat
2 parents 61d6710 + efe0688 commit efeb012

File tree

9 files changed

+256
-248
lines changed

9 files changed

+256
-248
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ It is then possible to make an automation to set all HA devices ready for peak p
282282

283283
## Statistic for energy
284284
Six attributes are added to track energy usage for devices:
285-
- hourly_kwh_count: total count of kwh hourly usage
286-
- daily_kwh_count: total count of kwh daily usage
287-
- monthly_kwh_count: total count of kwh monthly usage
288285
- hourly_kwh: kwh used for last hour
289286
- daily_kwh: kwh used for last day
290287
- monthly_kwh: kwh used for last month
288+
- current_hour_kwh": kwh used during current hour
289+
- current_today_kwh: kwh used during current day
290+
- current_month_kwh: kwh used during current month
291291

292292
They are polled from Neviweb every 30 minutes. The first polling start 5 minutes after HA restart.
293293

custom_components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"neviweb130": {
3-
"version": "3.0.4",
3+
"version": "3.0.5",
44
"local_location": "/custom_components/neviweb130/__init__.py",
55
"remote_location": "https://github.com/claudegel/sinope-130/tree/master/custom_components/__init__.py",
66
"visit_repo": "https://github.com/claudegel/sinope-130",

custom_components/neviweb130/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def get_device_monthly_stats(self, device_id):
635635
# Http requests
636636
try:
637637
raw_res = requests.get(
638-
DEVICE_DATA_URL + str(device_id) + "/energy/monthly",
638+
DEVICE_DATA_URL + str(device_id) + "/consumption/monthly",
639639
headers=self._headers,
640640
cookies=self._cookies,
641641
timeout=self._timeout,
@@ -661,7 +661,7 @@ def get_device_daily_stats(self, device_id):
661661
# Http requests
662662
try:
663663
raw_res = requests.get(
664-
DEVICE_DATA_URL + str(device_id) + "/energy/daily",
664+
DEVICE_DATA_URL + str(device_id) + "/consumption/daily",
665665
headers=self._headers,
666666
cookies=self._cookies,
667667
timeout=self._timeout,
@@ -687,7 +687,7 @@ def get_device_hourly_stats(self, device_id):
687687
# Http requests
688688
try:
689689
raw_res = requests.get(
690-
DEVICE_DATA_URL + str(device_id) + "/energy/hourly",
690+
DEVICE_DATA_URL + str(device_id) + "/consumption/hourly",
691691
headers=self._headers,
692692
cookies=self._cookies,
693693
timeout=self._timeout,

custom_components/neviweb130/climate.py

Lines changed: 108 additions & 99 deletions
Large diffs are not rendered by default.

custom_components/neviweb130/light.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,12 @@ def __init__(self, data, device_info, name, sku, firmware):
358358
self._id = device_info["id"]
359359
self._device_model = device_info["signature"]["model"]
360360
self._device_model_cfg = device_info["signature"]["modelCfg"]
361-
self._hour_energy_kwh_count = None
362-
self._today_energy_kwh_count = None
363-
self._month_energy_kwh_count = None
364-
self._hour_kwh = None
365-
self._today_kwh = None
366-
self._month_kwh = None
361+
self._hour_kwh = 0
362+
self._today_kwh = 0
363+
self._month_kwh = 0
364+
self._current_hour_kwh = 0
365+
self._current_today_kwh = 0
366+
self._current_month_kwh = 0
367367
self._brightness_pct = 0
368368
self._keypad = "Unlocked"
369369
self._timer = 0
@@ -499,12 +499,12 @@ def extra_state_attributes(self):
499499
"timer": self._timer,
500500
"led_on": self._led_on,
501501
"led_off": self._led_off,
502-
"hourly_kwh_count": self._hour_energy_kwh_count,
503-
"daily_kwh_count": self._today_energy_kwh_count,
504-
"monthly_kwh_count": self._month_energy_kwh_count,
505502
"hourly_kwh": self._hour_kwh,
506503
"daily_kwh": self._today_kwh,
507504
"monthly_kwh": self._month_kwh,
505+
"current_hour_kwh": self._current_hour_kwh,
506+
"current_today_kwh": self._current_today_kwh,
507+
"current_month_kwh": self._current_month_kwh,
508508
"sku": self._sku,
509509
"device_model": str(self._device_model),
510510
"device_model_cfg": self._device_model_cfg,
@@ -630,29 +630,32 @@ def do_stat(self, start):
630630
device_hourly_stats = self._client.get_device_hourly_stats(self._id)
631631
# _LOGGER.warning("%s device_hourly_stats = %s", self._name, device_hourly_stats)
632632
if device_hourly_stats is not None and len(device_hourly_stats) > 1:
633-
self._hour_energy_kwh_count = device_hourly_stats[1]["counter"] / 1000
634-
self._hour_kwh = device_hourly_stats[1]["period"] / 1000
633+
n = len(device_hourly_stats) - 2
634+
self._hour_kwh = device_hourly_stats[n]["period"] / 1000
635+
self._current_hour_kwh = device_hourly_stats[n + 1]["period"] / 1000
635636
else:
636-
self._hour_energy_kwh_count = 0
637637
self._hour_kwh = 0
638+
self._current_hour_kwh = 0
638639
_LOGGER.warning("Got None for device_hourly_stats")
639640
device_daily_stats = self._client.get_device_daily_stats(self._id)
640641
# _LOGGER.warning("%s device_daily_stats = %s", self._name, device_daily_stats)
641642
if device_daily_stats is not None and len(device_daily_stats) > 1:
642-
self._today_energy_kwh_count = device_daily_stats[0]["counter"] / 1000
643-
self._today_kwh = device_daily_stats[0]["period"] / 1000
643+
n = len(device_daily_stats) - 2
644+
self._today_kwh = device_daily_stats[n]["period"] / 1000
645+
self._current_today_kwh = device_daily_stats[n + 1]["period"] / 1000
644646
else:
645-
self._today_energy_kwh_count = 0
646647
self._today_kwh = 0
648+
self._current_today_kwh = 0
647649
_LOGGER.warning("Got None for device_daily_stats")
648650
device_monthly_stats = self._client.get_device_monthly_stats(self._id)
649651
# _LOGGER.warning("%s device_monthly_stats = %s", self._name, device_monthly_stats)
650652
if device_monthly_stats is not None and len(device_monthly_stats) > 1:
651-
self._month_energy_kwh_count = device_monthly_stats[0]["counter"] / 1000
652-
self._month_kwh = device_monthly_stats[0]["period"] / 1000
653+
n = len(device_monthly_stats) - 2
654+
self._month_kwh = device_monthly_stats[n]["period"] / 1000
655+
self._current_month_kwh = device_monthly_stats[n + 1]["period"] / 1000
653656
else:
654-
self._month_energy_kwh_count = 0
655657
self._month_kwh = 0
658+
self._current_month_kwh = 0
656659
_LOGGER.warning("Got None for device_monthly_stats")
657660
self._energy_stat_time = time.time()
658661
if self._energy_stat_time == 0:
@@ -793,12 +796,12 @@ def __init__(self, data, device_info, name, sku, firmware):
793796
self._id = device_info["id"]
794797
self._device_model = device_info["signature"]["model"]
795798
self._device_model_cfg = device_info["signature"]["modelCfg"]
796-
self._hour_energy_kwh_count = None
797-
self._today_energy_kwh_count = None
798-
self._month_energy_kwh_count = None
799-
self._hour_kwh = None
800-
self._today_kwh = None
801-
self._month_kwh = None
799+
self._hour_kwh = 0
800+
self._today_kwh = 0
801+
self._month_kwh = 0
802+
self._current_hour_kwh = 0
803+
self._current_today_kwh = 0
804+
self._current_month_kwh = 0
802805
self._brightness_pct = 0
803806
self._keypad = "Unlocked"
804807
self._timer = 0
@@ -908,12 +911,12 @@ def extra_state_attributes(self):
908911
"timer": self._timer,
909912
"led_on": self._led_on,
910913
"led_off": self._led_off,
911-
"hourly_kwh_count": self._hour_energy_kwh_count,
912-
"daily_kwh_count": self._today_energy_kwh_count,
913-
"monthly_kwh_count": self._month_energy_kwh_count,
914914
"hourly_kwh": self._hour_kwh,
915915
"daily_kwh": self._today_kwh,
916916
"monthly_kwh": self._month_kwh,
917+
"current_hour_kwh": self._current_hour_kwh,
918+
"current_today_kwh": self._current_today_kwh,
919+
"current_month_kwh": self._current_month_kwh,
917920
"sku": self._sku,
918921
"device_model": str(self._device_model),
919922
"device_model_cfg": self._device_model_cfg,
@@ -938,12 +941,12 @@ def __init__(self, data, device_info, name, sku, firmware):
938941
self._id = device_info["id"]
939942
self._device_model = device_info["signature"]["model"]
940943
self._device_model_cfg = device_info["signature"]["modelCfg"]
941-
self._hour_energy_kwh_count = None
942-
self._today_energy_kwh_count = None
943-
self._month_energy_kwh_count = None
944-
self._hour_kwh = None
945-
self._today_kwh = None
946-
self._month_kwh = None
944+
self._hour_kwh = 0
945+
self._today_kwh = 0
946+
self._month_kwh = 0
947+
self._current_hour_kwh = 0
948+
self._current_today_kwh = 0
949+
self._current_month_kwh = 0
947950
self._brightness_pct = 0
948951
self._keypad = "Unlocked"
949952
self._timer = 0
@@ -1064,12 +1067,12 @@ def extra_state_attributes(self):
10641067
"timer": self._timer,
10651068
"led_on": self._led_on,
10661069
"led_off": self._led_off,
1067-
"hourly_kwh_count": self._hour_energy_kwh_count,
1068-
"daily_kwh_count": self._today_energy_kwh_count,
1069-
"monthly_kwh_count": self._month_energy_kwh_count,
10701070
"hourly_kwh": self._hour_kwh,
10711071
"daily_kwh": self._today_kwh,
10721072
"monthly_kwh": self._month_kwh,
1073+
"current_hour_kwh": self._current_hour_kwh,
1074+
"current_today_kwh": self._current_today_kwh,
1075+
"current_month_kwh": self._current_month_kwh,
10731076
"sku": self._sku,
10741077
"device_model": str(self._device_model),
10751078
"device_model_cfg": self._device_model_cfg,

custom_components/neviweb130/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
"dependencies": [],
88
"requirements": [],
99
"iot_class": "cloud_polling",
10-
"version": "3.0.4",
10+
"version": "3.0.5",
1111
"homeassistant": "2025.1.1"
1212
}

custom_components/neviweb130/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
"""Default parameters values."""
4040

41-
VERSION = "3.0.4"
41+
VERSION = "3.0.5"
4242
SCAN_INTERVAL = timedelta(seconds=540)
4343
HOMEKIT_MODE = False
4444
STAT_INTERVAL = 1800

0 commit comments

Comments
 (0)