mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-04-26 16:46:23 +00:00
Return None instead of raising an exception on missing, valid emeter keys (#146)
Fixes #142 Also, update the pre-commit hooks to their newest versions
This commit is contained in:
parent
2fe1b209d0
commit
1ee4757fdb
@ -1,6 +1,6 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v2.4.0
|
rev: v3.4.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
@ -10,30 +10,30 @@ repos:
|
|||||||
- id: check-ast
|
- id: check-ast
|
||||||
|
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: v1.25.2
|
rev: v2.10.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: ['--py36-plus']
|
args: ['--py36-plus']
|
||||||
|
|
||||||
- repo: https://github.com/python/black
|
- repo: https://github.com/python/black
|
||||||
rev: stable
|
rev: 20.8b1
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: black
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://gitlab.com/pycqa/flake8
|
||||||
rev: v2.3.0
|
rev: 3.9.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: flake8
|
||||||
additional_dependencies: [flake8-docstrings]
|
additional_dependencies: [flake8-docstrings]
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-isort
|
- repo: https://github.com/pre-commit/mirrors-isort
|
||||||
rev: v4.3.21
|
rev: v5.7.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: isort
|
||||||
additional_dependencies: [toml]
|
additional_dependencies: [toml]
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v0.740
|
rev: v0.812
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
# args: [--no-strict-optional, --ignore-missing-imports]
|
# args: [--no-strict-optional, --ignore-missing-imports]
|
||||||
|
@ -8,6 +8,7 @@ from pprint import pprint as pp
|
|||||||
import click
|
import click
|
||||||
import dpkt
|
import dpkt
|
||||||
from dpkt.ethernet import ETH_TYPE_IP, Ethernet
|
from dpkt.ethernet import ETH_TYPE_IP, Ethernet
|
||||||
|
|
||||||
from kasa.protocol import TPLinkSmartHomeProtocol
|
from kasa.protocol import TPLinkSmartHomeProtocol
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ Module-specific errors are raised as `SmartDeviceException` and are expected
|
|||||||
to be handled by the user of the library.
|
to be handled by the user of the library.
|
||||||
"""
|
"""
|
||||||
from importlib_metadata import version # type: ignore
|
from importlib_metadata import version # type: ignore
|
||||||
|
|
||||||
from kasa.discover import Discover
|
from kasa.discover import Discover
|
||||||
from kasa.exceptions import SmartDeviceException
|
from kasa.exceptions import SmartDeviceException
|
||||||
from kasa.protocol import TPLinkSmartHomeProtocol
|
from kasa.protocol import TPLinkSmartHomeProtocol
|
||||||
|
@ -87,7 +87,8 @@ class EmeterStatus(dict):
|
|||||||
if i.startswith(item):
|
if i.startswith(item):
|
||||||
return self.__getitem__(i) / 1000
|
return self.__getitem__(i) / 1000
|
||||||
|
|
||||||
raise SmartDeviceException("Unable to find a value for '%s'" % item)
|
_LOGGER.debug(f"Unable to find value for '{item}'")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def requires_update(f):
|
def requires_update(f):
|
||||||
|
@ -115,3 +115,19 @@ async def test_current_consumption(dev):
|
|||||||
assert x >= 0.0
|
assert x >= 0.0
|
||||||
else:
|
else:
|
||||||
assert await dev.current_consumption() is None
|
assert await dev.current_consumption() is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_emeterstatus_missing_current():
|
||||||
|
"""KL125 does not report 'current' for emeter."""
|
||||||
|
from kasa import EmeterStatus
|
||||||
|
|
||||||
|
regular = EmeterStatus(
|
||||||
|
{"err_code": 0, "power_mw": 0, "total_wh": 13, "current_ma": 123}
|
||||||
|
)
|
||||||
|
assert regular["current"] == 0.123
|
||||||
|
|
||||||
|
with pytest.raises(KeyError):
|
||||||
|
regular["invalid_key"]
|
||||||
|
|
||||||
|
missing_current = EmeterStatus({"err_code": 0, "power_mw": 0, "total_wh": 13})
|
||||||
|
assert missing_current["current"] is None
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import xdoctest
|
import xdoctest
|
||||||
|
|
||||||
from kasa.tests.conftest import get_device_for_file
|
from kasa.tests.conftest import get_device_for_file
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user