Skip to content

Commit

Permalink
Merge branch 'rytilahti:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
smmoroz authored Feb 18, 2024
2 parents cb2297f + 35a8773 commit 74852ee
Show file tree
Hide file tree
Showing 36 changed files with 701 additions and 678 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: check-ast

- repo: https://github.com/psf/black
rev: 23.10.0
rev: 24.2.0
hooks:
- id: black
language_version: python3
Expand All @@ -36,20 +36,20 @@ repos:
# args: [--in-place, --wrap-summaries, '88', --wrap-descriptions, '88', --black

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-docstrings, flake8-bugbear, flake8-builtins, flake8-print, flake8-pytest-style, flake8-return, flake8-simplify, flake8-annotations]

- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
rev: 1.7.7
hooks:
- id: bandit
args: [-x, 'tests', -x, '**/test_*.py']


- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [types-attrs, types-PyYAML, types-requests, types-pytz, types-croniter, types-freezegun]
Expand Down
1 change: 1 addition & 0 deletions miio/click_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This file contains common functions for cli tools.
"""

import ast
import ipaddress
import json
Expand Down
1 change: 1 addition & 0 deletions miio/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
If you are developing an integration, prefer :func:`~miio.devicestatus.sensor`, :func:`~miio.devicestatus.setting`, and
:func:`~miio.devicestatus.action` decorators over creating the descriptors manually.
"""

from enum import Enum, Flag, auto
from typing import Any, Callable, Dict, List, Optional, Type

Expand Down
1 change: 1 addition & 0 deletions miio/devtools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Command-line interface for devtools."""

import logging

import click
Expand Down
3 changes: 2 additions & 1 deletion miio/devtools/pcapparser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Parse PCAP files for miio traffic."""

from collections import Counter, defaultdict
from ipaddress import ip_address
from pprint import pformat as pf
Expand Down Expand Up @@ -51,7 +52,7 @@ def read_payloads_from_file(file, tokens: List[str]):
try:
decrypted = Message.parse(data, token=bytes.fromhex(token))
break
except BaseException:
except BaseException: # noqa: B036
continue

if decrypted is None:
Expand Down
1 change: 1 addition & 0 deletions miio/devtools/simulators/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common functionalities for miio and miot simulators."""

from hashlib import md5


Expand Down
1 change: 1 addition & 0 deletions miio/devtools/simulators/miiosimulator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implementation of miio simulator."""

import asyncio
import json
import logging
Expand Down
1 change: 1 addition & 0 deletions miio/identifiers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Compat layer for homeassistant."""

from enum import Enum, auto


Expand Down
6 changes: 3 additions & 3 deletions miio/integrations/cgllc/airmonitor/airqualitymonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ def off(self):
@command(
click.argument("display_clock", type=bool),
default_output=format_output(
lambda led: "Turning on display clock"
if led
else "Turning off display clock"
lambda led: (
"Turning on display clock" if led else "Turning off display clock"
)
),
)
def set_display_clock(self, display_clock: bool):
Expand Down
8 changes: 5 additions & 3 deletions miio/integrations/chuangmi/camera/chuangmi_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,11 @@ def set_motion_sensitivity(self, sensitivity: MotionDetectionSensitivity):
"""Set motion sensitivity (high, low)."""
return self.send(
"set_motion_region",
CONST_HIGH_SENSITIVITY
if sensitivity == MotionDetectionSensitivity.High
else CONST_LOW_SENSITIVITY,
(
CONST_HIGH_SENSITIVITY
if sensitivity == MotionDetectionSensitivity.High
else CONST_LOW_SENSITIVITY
),
)

@command(
Expand Down
6 changes: 3 additions & 3 deletions miio/integrations/chuangmi/plug/chuangmi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def usb_off(self):
@command(
click.argument("wifi_led", type=bool),
default_output=format_output(
lambda wifi_led: "Turning on WiFi LED"
if wifi_led
else "Turning off WiFi LED"
lambda wifi_led: (
"Turning on WiFi LED" if wifi_led else "Turning off WiFi LED"
)
),
)
def set_wifi_led(self, wifi_led: bool):
Expand Down
8 changes: 5 additions & 3 deletions miio/integrations/chuangmi/remote/chuangmi_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ def play(self, command: str):
@command(
click.argument("indicator_led", type=bool),
default_output=format_output(
lambda indicator_led: "Turning on indicator LED"
if indicator_led
else "Turning off indicator LED"
lambda indicator_led: (
"Turning on indicator LED"
if indicator_led
else "Turning off indicator LED"
)
),
)
def set_indicator_led(self, indicator_led: bool):
Expand Down
8 changes: 5 additions & 3 deletions miio/integrations/deerma/humidifier/airhumidifier_mjjsq.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ def set_target_humidity(self, humidity: int):
@command(
click.argument("protection", type=bool),
default_output=format_output(
lambda protection: "Turning on wet protection"
if protection
else "Turning off wet protection"
lambda protection: (
"Turning on wet protection"
if protection
else "Turning off wet protection"
)
),
)
def set_wet_protection(self, protection: bool):
Expand Down
6 changes: 3 additions & 3 deletions miio/integrations/dmaker/fan/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ def set_angle(self, angle: int):
@command(
click.argument("oscillate", type=bool),
default_output=format_output(
lambda oscillate: "Turning on oscillate"
if oscillate
else "Turning off oscillate"
lambda oscillate: (
"Turning on oscillate" if oscillate else "Turning off oscillate"
)
),
)
def set_oscillate(self, oscillate: bool):
Expand Down
12 changes: 6 additions & 6 deletions miio/integrations/dmaker/fan/fan_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ def set_angle(self, angle: int):
@command(
click.argument("oscillate", type=bool),
default_output=format_output(
lambda oscillate: "Turning on oscillate"
if oscillate
else "Turning off oscillate"
lambda oscillate: (
"Turning on oscillate" if oscillate else "Turning off oscillate"
)
),
)
def set_oscillate(self, oscillate: bool):
Expand Down Expand Up @@ -527,9 +527,9 @@ def set_speed(self, speed: int):
@command(
click.argument("oscillate", type=bool),
default_output=format_output(
lambda oscillate: "Turning on oscillate"
if oscillate
else "Turning off oscillate"
lambda oscillate: (
"Turning on oscillate" if oscillate else "Turning off oscillate"
)
),
)
def set_oscillate(self, oscillate: bool):
Expand Down
23 changes: 14 additions & 9 deletions miio/integrations/genericmiot/genericmiot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from functools import partial
from typing import Dict, Optional
from typing import Dict, List, Optional

from miio import MiotDevice
from miio.click_common import command
Expand Down Expand Up @@ -45,6 +45,7 @@ def __init__(

self._actions: Dict[str, ActionDescriptor] = {}
self._properties: Dict[str, PropertyDescriptor] = {}
self._status_query: List[Dict] = []

def initialize_model(self):
"""Initialize the miot model and create descriptions."""
Expand All @@ -59,17 +60,13 @@ def initialize_model(self):
@command()
def status(self) -> GenericMiotStatus:
"""Return status based on the miot model."""
properties = []
for _, prop in self.sensors().items():
extras = prop.extras
prop = extras["miot_property"]
q = {"siid": prop.siid, "piid": prop.piid, "did": prop.name}
properties.append(q)
if not self._initialized:
self._initialize_descriptors()

# TODO: max properties needs to be made configurable (or at least splitted to avoid too large udp datagrams
# some devices are stricter: https://github.com/rytilahti/python-miio/issues/1550#issuecomment-1303046286
response = self.get_properties(
properties, property_getter="get_properties", max_properties=10
self._status_query, property_getter="get_properties", max_properties=10
)

return GenericMiotStatus(response, self)
Expand Down Expand Up @@ -105,7 +102,15 @@ def _create_properties(self, serv: MiotService):

desc = prop.get_descriptor()

if desc.access & AccessFlags.Write:
# Add readable properties to the status query
if AccessFlags.Read in desc.access:
extras = prop.extras
prop = extras["miot_property"]
q = {"siid": prop.siid, "piid": prop.piid, "did": prop.name}
self._status_query.append(q)

# Bind setter to the descriptor
if AccessFlags.Write in desc.access:
desc.setter = partial(
self.set_property_by, prop.siid, prop.piid, name=prop.name
)
Expand Down
6 changes: 3 additions & 3 deletions miio/integrations/leshow/fan/fan_leshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def set_speed(self, speed: int):
@command(
click.argument("oscillate", type=bool),
default_output=format_output(
lambda oscillate: "Turning on oscillate"
if oscillate
else "Turning off oscillate"
lambda oscillate: (
"Turning on oscillate" if oscillate else "Turning off oscillate"
)
),
)
def set_oscillate(self, oscillate: bool):
Expand Down
1 change: 1 addition & 0 deletions miio/integrations/lumi/camera/aqaracamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.. todo:: add sdcard status & fix all TODOS
.. todo:: add tests
"""

import logging
from enum import IntEnum
from typing import Any, Dict
Expand Down
8 changes: 5 additions & 3 deletions miio/integrations/philips/light/philips_rwread.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ def delay_off(self, seconds: int):
@command(
click.argument("motion_detection", type=bool),
default_output=format_output(
lambda motion_detection: "Turning on motion detection"
if motion_detection
else "Turning off motion detection"
lambda motion_detection: (
"Turning on motion detection"
if motion_detection
else "Turning off motion detection"
)
),
)
def set_motion_detection(self, motion_detection: bool):
Expand Down
6 changes: 6 additions & 0 deletions miio/integrations/roborock/vacuum/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@
ROCKROBO_T7SPLUS = "roborock.vacuum.a23"
ROCKROBO_S7_MAXV = "roborock.vacuum.a27"
ROCKROBO_S7_PRO_ULTRA = "roborock.vacuum.a62"
ROCKROBO_S8_PRO_ULTRA = "roborock.vacuum.a70"
ROCKROBO_Q5 = "roborock.vacuum.a34"
ROCKROBO_Q7_MAX = "roborock.vacuum.a38"
ROCKROBO_Q7PLUS = "roborock.vacuum.a40"
ROCKROBO_Q_REVO = "roborock.vacuum.a75"
ROCKROBO_G10S = "roborock.vacuum.a46"
ROCKROBO_G10 = "roborock.vacuum.a29"

Expand All @@ -103,9 +105,11 @@
ROCKROBO_S7,
ROCKROBO_S7_MAXV,
ROCKROBO_S7_PRO_ULTRA,
ROCKROBO_S8_PRO_ULTRA,
ROCKROBO_Q5,
ROCKROBO_Q7_MAX,
ROCKROBO_Q7PLUS,
ROCKROBO_Q_REVO,
ROCKROBO_G10,
ROCKROBO_G10S,
ROCKROBO_S6_MAXV,
Expand All @@ -118,7 +122,9 @@
AUTO_EMPTY_MODELS = [
ROCKROBO_S7,
ROCKROBO_S7_MAXV,
ROCKROBO_S8_PRO_ULTRA,
ROCKROBO_Q7_MAX,
ROCKROBO_Q_REVO,
]


Expand Down
1 change: 0 additions & 1 deletion miio/integrations/roidmi/vacuum/roidmivacuum_miot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Vacuum Eve Plus (roidmi.vacuum.v60)"""


import json
import logging
import math
Expand Down
1 change: 1 addition & 0 deletions miio/integrations/tinymu/toiletlid/test_toiletlid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Filter remaining: 100%
Filter remaining time: 180
"""

from unittest import TestCase

import pytest
Expand Down
1 change: 1 addition & 0 deletions miio/integrations/viomi/vacuum/viomivacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- Clean History Path - MISSING (historyPath)
- Map plan - MISSING (map_plan)
"""

import itertools
import logging
import time
Expand Down
24 changes: 13 additions & 11 deletions miio/integrations/xiaomi/aircondition/airconditioner_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ def set_dryer(self, dryer: bool):
@command(
click.argument("sleep_mode", type=bool),
default_output=format_output(
lambda sleep_mode: "Turning on sleep mode"
if sleep_mode
else "Turning off sleep mode"
lambda sleep_mode: (
"Turning on sleep mode" if sleep_mode else "Turning off sleep mode"
)
),
)
def set_sleep_mode(self, sleep_mode: bool):
Expand All @@ -400,9 +400,11 @@ def set_fan_speed(self, fan_speed: FanSpeed):
@command(
click.argument("vertical_swing", type=bool),
default_output=format_output(
lambda vertical_swing: "Turning on vertical swing"
if vertical_swing
else "Turning off vertical swing"
lambda vertical_swing: (
"Turning on vertical swing"
if vertical_swing
else "Turning off vertical swing"
)
),
)
def set_vertical_swing(self, vertical_swing: bool):
Expand Down Expand Up @@ -443,11 +445,11 @@ def set_fan_speed_percent(self, fan_speed_percent):
click.argument("minutes", type=int),
click.argument("delay_on", type=bool),
default_output=format_output(
lambda minutes, delay_on: "Setting timer to delay on after "
+ str(minutes)
+ " minutes"
if delay_on
else "Setting timer to delay off after " + str(minutes) + " minutes"
lambda minutes, delay_on: (
"Setting timer to delay on after " + str(minutes) + " minutes"
if delay_on
else "Setting timer to delay off after " + str(minutes) + " minutes"
)
),
)
def set_timer(self, minutes, delay_on):
Expand Down
Loading

0 comments on commit 74852ee

Please sign in to comment.