Skip to content
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

Skip warning if the unknown model is reported on a base class #1243

Merged
merged 2 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions miio/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ def _fetch_info(self) -> DeviceInfo:
devinfo = DeviceInfo(self.send("miIO.info"))
self._info = devinfo
_LOGGER.debug("Detected model %s", devinfo.model)
if devinfo.model not in self.supported_models:
cls = self.__class__.__name__
bases = ["Device", "MiotDevice"]
if devinfo.model not in self.supported_models and cls not in bases:
_LOGGER.warning(
"Found an unsupported model '%s' for class '%s'. If this is working for you, please open an issue at https://github.com/rytilahti/python-miio/",
self.model,
self.__class__.__name__,
cls,
)

return devinfo
Expand Down
19 changes: 13 additions & 6 deletions miio/tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from miio import Device
from miio import Device, MiotDevice, Vacuum
from miio.exceptions import DeviceInfoUnavailableException, PayloadDecodeException


Expand Down Expand Up @@ -59,7 +59,7 @@ def test_unavailable_device_info_raises(mocker):

def test_model_autodetection(mocker):
"""Make sure info() gets called if the model is unknown."""
info = mocker.patch("miio.Device.info")
info = mocker.patch("miio.Device._fetch_info")
_ = mocker.patch("miio.Device.send")

d = Device("127.0.0.1", "68ffffffffffffffffffffffffffffff")
Expand All @@ -83,15 +83,22 @@ def test_forced_model(mocker):
info.assert_not_called()


def test_missing_supported(mocker, caplog):
@pytest.mark.parametrize(
"cls,hidden", [(Device, True), (MiotDevice, True), (Vacuum, False)]
)
def test_missing_supported(mocker, caplog, cls, hidden):
"""Make sure warning is logged if the device is unsupported for the class."""
_ = mocker.patch("miio.Device.send")

d = Device("127.0.0.1", "68ffffffffffffffffffffffffffffff")
d = cls("127.0.0.1", "68ffffffffffffffffffffffffffffff")
d._fetch_info()

assert "Found an unsupported model" in caplog.text
assert "for class 'Device'" in caplog.text
if hidden:
assert "Found an unsupported model" not in caplog.text
assert f"for class '{cls.__name__}'" not in caplog.text
else:
assert "Found an unsupported model" in caplog.text
assert f"for class '{cls.__name__}'" in caplog.text


@pytest.mark.parametrize("cls", Device.__subclasses__())
Expand Down