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

Re-add mapping parameter to MiotDevice ctor #985

Merged
merged 1 commit into from
Mar 24, 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
19 changes: 18 additions & 1 deletion miio/miot_device.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from enum import Enum
from functools import partial
from typing import Any, Union
from typing import Any, Dict, Union

import click

Expand Down Expand Up @@ -30,6 +30,23 @@ class MiotDevice(Device):

mapping = None

def __init__(
self,
ip: str = None,
token: str = None,
start_id: int = 0,
debug: int = 0,
lazy_discover: bool = True,
timeout: int = None,
*,
mapping: Dict = None,
):
"""Overloaded to accept keyword-only `mapping` parameter."""
if mapping is not None:
self.mapping = mapping

super().__init__(ip, token, start_id, debug, lazy_discover, timeout)

def get_properties_for_mapping(self, *, max_properties=15) -> list:
"""Retrieve raw properties based on mapping."""

Expand Down
12 changes: 12 additions & 0 deletions miio/tests/test_miotdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ def dev(module_mocker):
return device


def test_ctor_mapping():
"""Make sure the constructor accepts the mapping parameter."""
dev = MiotDevice("127.0.0.1", "68ffffffffffffffffffffffffffffff")
assert dev.mapping is None

test_mapping = {}
dev2 = MiotDevice(
"127.0.0.1", "68ffffffffffffffffffffffffffffff", mapping=test_mapping
)
assert dev2.mapping == test_mapping


def test_get_property_by(dev):
siid = 1
piid = 2
Expand Down