Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions kasa/smartstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from kasa.smartdevice import (
DeviceType,
EmeterStatus,
SmartDevice,
SmartDeviceException,
requires_update,
Expand Down Expand Up @@ -154,6 +155,35 @@ async def set_alias(self, alias: str) -> None:
"""
return await super().set_alias(alias)

@requires_update
async def get_emeter_realtime(self) -> EmeterStatus:
"""Retrieve current energy readings."""
if not self.has_emeter:
raise SmartDeviceException("Device has no emeter")

plug_emeter = False
for plug in self.children:
if plug.has_emeter:
plug_emeter = True

if not plug_emeter:
return EmeterStatus(await self._query_helper(self.emeter_type, "get_realtime"))

emeter_rt: DefaultDict[int, float] = defaultdict(lambda: 0.0)
count = 0
for plug in self.children:
if not plug.has_emeter:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a real-world case, where some sockets on the same strip have and some sockets don't have emeter? If not I think this would be redundant

continue
count += 1
plug_emeter_rt = await plug.get_emeter_realtime()
for field, value in plug_emeter_rt.items():
emeter_rt[field] += value

# Voltage is averaged
emeter_rt['voltage_mv'] /= count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the idea here, but have you ever noticed the individual plugs reporting different voltage? Normally you should get the same voltage from each child-plug.


return EmeterStatus(emeter_rt)

@requires_update
async def get_emeter_daily(
self, year: int = None, month: int = None, kwh: bool = True
Expand Down Expand Up @@ -247,12 +277,6 @@ def led(self) -> bool:
"""
return False

@property # type: ignore
@requires_update
def has_emeter(self) -> bool:
"""Children have no emeter to my knowledge."""
return False

@property # type: ignore
@requires_update
def device_id(self) -> str:
Expand Down