-
-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
genericmiot: skip properties with invalid values (#1830)
`GenericMiotStatus` now ignores invalid properties (i.e., ones with missing values) and properties where the error code != 0.
- Loading branch information
Showing
2 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
||
from ..status import GenericMiotStatus | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def mockdev(): | ||
yield Mock() | ||
|
||
|
||
VALID_RESPONSE = {"code": 0, "did": "valid-response", "piid": 1, "siid": 1, "value": 1} | ||
|
||
|
||
@pytest.mark.parametrize("key", ("did", "piid", "siid", "value", "code")) | ||
def test_response_with_missing_value(key, mockdev, caplog: pytest.LogCaptureFixture): | ||
"""Verify that property responses without necessary keys are ignored.""" | ||
caplog.set_level(logging.DEBUG) | ||
|
||
prop = {"code": 0, "did": f"no-{key}-in-response", "piid": 1, "siid": 1, "value": 1} | ||
prop.pop(key) | ||
|
||
status = GenericMiotStatus([VALID_RESPONSE, prop], mockdev) | ||
assert f"Ignoring due to missing '{key}'" in caplog.text | ||
assert len(status.data) == 1 | ||
|
||
|
||
@pytest.mark.parametrize("code", (-123, 123)) | ||
def test_response_with_error_codes(code, mockdev, caplog: pytest.LogCaptureFixture): | ||
caplog.set_level(logging.WARNING) | ||
|
||
did = f"error-code-{code}" | ||
prop = {"code": code, "did": did, "piid": 1, "siid": 1} | ||
status = GenericMiotStatus([VALID_RESPONSE, prop], mockdev) | ||
assert f"Ignoring due to error code '{code}'" in caplog.text | ||
assert len(status.data) == 1 |