Skip to content

Commit

Permalink
Merge branch 'master' into replace-utcnow
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti authored Sep 14, 2023
2 parents 3f268d3 + 2546b04 commit 9bcd715
Show file tree
Hide file tree
Showing 10 changed files with 524 additions and 353 deletions.
28 changes: 28 additions & 0 deletions miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,32 @@

from miio.discovery import Discovery


def __getattr__(name):
"""Create deprecation warnings on classes that are going away."""
from warnings import warn

current_globals = globals()

def _is_miio_integration(x):
"""Return True if miio.integrations is in the module 'path'."""
module_ = current_globals[x]
if "miio.integrations" in str(module_):
return True

return False

deprecated_module_mapping = {
str(x): current_globals[x] for x in current_globals if _is_miio_integration(x)
}
if new_module := deprecated_module_mapping.get(name):
warn(
f"Importing {name} directly from 'miio' is deprecated, import {new_module} or use DeviceFactory.create() instead",
DeprecationWarning,
)
return globals()[new_module.__name__]

raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


__version__ = version("python-miio")
6 changes: 5 additions & 1 deletion miio/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from typing import TYPE_CHECKING, Dict, Optional

import click
from pydantic import BaseModel, Field

try:
from pydantic.v1 import BaseModel, Field
except ImportError:
from pydantic import BaseModel, Field

try:
from rich import print as echo
Expand Down
6 changes: 5 additions & 1 deletion miio/devtools/simulators/miiosimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
from typing import List, Optional, Union

import click
from pydantic import BaseModel, Field, PrivateAttr

try:
from pydantic.v1 import BaseModel, Field, PrivateAttr
except ImportError:
from pydantic import BaseModel, Field, PrivateAttr
from yaml import safe_load

from miio import PushServer
Expand Down
5 changes: 4 additions & 1 deletion miio/devtools/simulators/miotsimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from typing import List, Union

import click
from pydantic import Field, validator

try:
from pydantic.v1 import Field, validator
except ImportError:
from pydantic import Field, validator
from miio import PushServer
from miio.miot_cloud import MiotCloud
from miio.miot_models import DeviceModel, MiotAccess, MiotProperty, MiotService
Expand Down
6 changes: 5 additions & 1 deletion miio/miot_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import appdirs
from micloud.miotspec import MiotSpec
from pydantic import BaseModel, Field

try:
from pydantic.v1 import BaseModel, Field
except ImportError:
from pydantic import BaseModel, Field

from miio import CloudException
from miio.miot_models import DeviceModel
Expand Down
5 changes: 4 additions & 1 deletion miio/miot_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from enum import Enum
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field, PrivateAttr, root_validator
try:
from pydantic.v1 import BaseModel, Field, PrivateAttr, root_validator
except ImportError:
from pydantic import BaseModel, Field, PrivateAttr, root_validator

from .descriptors import (
AccessFlags,
Expand Down
16 changes: 16 additions & 0 deletions miio/tests/test_miio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Tests for the main module."""
import pytest

import miio


@pytest.mark.parametrize(
("old_name", "new_name"),
[("RoborockVacuum", "miio.integrations.roborock.vacuum.vacuum.RoborockVacuum")],
)
def test_deprecation_warning(old_name, new_name):
"""Check that deprecation warning gets emitted for deprecated imports."""
with pytest.deprecated_call(
match=rf"Importing {old_name} directly from 'miio' is deprecated, import <class '{new_name}'> or use DeviceFactory.create\(\) instead"
):
miio.__getattr__(old_name)
6 changes: 5 additions & 1 deletion miio/tests/test_miot_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from pathlib import Path

import pytest
from pydantic import BaseModel

try:
from pydantic.v1 import BaseModel
except ImportError:
from pydantic import BaseModel

from miio.descriptors import (
AccessFlags,
Expand Down
795 changes: 450 additions & 345 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ tqdm = "^4"
micloud = { version = ">=0.6" }
croniter = ">=1"
defusedxml = "^0"
pydantic = "^1"
pydantic = ">=1,<3"
PyYAML = ">=5,<7"

# doc dependencies
sphinx = { version = "*", optional = true }
sphinx_click = { version = "*", optional = true }
sphinxcontrib-apidoc = { version = "*", optional = true }
sphinx_rtd_theme = { version = "*", optional = true }
sphinx_rtd_theme = { version = ">=1.3.0", optional = true }
myst-parser = { version = "*", optional = true }

# optionals
Expand Down

0 comments on commit 9bcd715

Please sign in to comment.