@@ -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 ,
0 commit comments