8000 Report 0 for instead of None for zero current and voltage by ryenitcher · Pull Request #1483 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Report 0 for instead of None for zero current and voltage #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2025
Merged
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
10 changes: 6 additions & 4 deletions kasa/smart/modules/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@
@raise_if_update_error
def current(self) -> float | None:
"""Return the current in A."""
ma = self.data.get("get_emeter_data", {}).get("current_ma")
return ma / 1000 if ma else None
if (ma := self.data.get("get_emeter_data", {}).get("current_ma")) is not None:
return ma / 1_000
return None

Check warning on line 131 in kasa/smart/modules/energy.py

View check run for this annotation

Codecov / codecov/patch

kasa/smart/modules/energy.py#L131

Added line #L131 was not covered by tests

@property
@raise_if_update_error
def voltage(self) -> float | None:
"""Get the current voltage in V."""
mv = self.data.get("get_emeter_data", {}).get("voltage_mv")
return mv / 1000 if mv else None
if (mv := self.data.get("get_emeter_data", {}).get("voltage_mv")) is not None:
return mv / 1_000
return None

Check warning on line 139 in kasa/smart/modules/energy.py

View check run for this annotation

Codecov / codecov/patch

kasa/smart/modules/energy.py#L139

Added line #L139 was not covered by tests

async def _deprecated_get_realtime(self) -> EmeterStatus:
"""Retrieve current energy readings."""
Expand Down
Loading
0