From a27e10e941c65de589d7bc609b0b3c49bdc31123 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Thu, 2 Apr 2020 17:00:56 +0200 Subject: [PATCH 1/5] Xiaomi camera (chuangmi.camera.ipc019): Add orientation controls Related to #655 --- miio/chuangmi_camera.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/miio/chuangmi_camera.py b/miio/chuangmi_camera.py index b385ca74d..41e3fe29b 100644 --- a/miio/chuangmi_camera.py +++ b/miio/chuangmi_camera.py @@ -1,14 +1,26 @@ """Xiaomi Chuangmi camera (chuangmi.camera.ipc009) support.""" +import enum import logging from typing import Any, Dict -from .click_common import command, format_output +import click + +from .click_common import EnumType, command, format_output from .device import Device _LOGGER = logging.getLogger(__name__) +class Direction(enum.Enum): + """Rotation direction.""" + + Right = 1 + Left = 2 + Up = 3 + Down = 4 + + class CameraStatus: """Container for status reports from the Xiaomi Chuangmi Camera.""" @@ -269,3 +281,10 @@ def night_mode_off(self): def night_mode_on(self): """Night mode always on.""" return self.send("set_night_mode", [2]) + + @command( + click.argument("mode", type=EnumType(Direction, False)), + default_output=format_output("Rotating to direction '{direction.name}'"), + ) + def rotate(self, direction: Direction): + return self.send("set_motor", {"operation": direction.value}) From a55efb5e918514bda44422bc3a597373ee34a2be Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sat, 4 Apr 2020 14:18:19 +0200 Subject: [PATCH 2/5] Add a note about ipc019 --- miio/chuangmi_camera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miio/chuangmi_camera.py b/miio/chuangmi_camera.py index 41e3fe29b..3eb969053 100644 --- a/miio/chuangmi_camera.py +++ b/miio/chuangmi_camera.py @@ -1,4 +1,4 @@ -"""Xiaomi Chuangmi camera (chuangmi.camera.ipc009) support.""" +"""Xiaomi Chuangmi camera (chuangmi.camera.ipc009, ipc019) support.""" import enum import logging From d901a72f96c140beab43e3ecd21721f0d911f865 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sat, 18 Apr 2020 17:27:38 +0200 Subject: [PATCH 3/5] add ipc019 to discovery, closes #671 --- miio/discovery.py | 1 + 1 file changed, 1 insertion(+) diff --git a/miio/discovery.py b/miio/discovery.py index 799fff597..9049fe760 100644 --- a/miio/discovery.py +++ b/miio/discovery.py @@ -113,6 +113,7 @@ "zhimi-airpurifier-mb3": AirPurifierMiot, # mb3 (3/3H) "zhimi-airpurifier-ma4": AirPurifierMiot, # ma4 (3) "chuangmi.camera.ipc009": ChuangmiCamera, + "chuangmi.camera.ipc019": ChuangmiCamera, "chuangmi-ir-v2": ChuangmiIr, "chuangmi-remote-h102a03_": ChuangmiIr, "zhimi-humidifier-v1": partial(AirHumidifier, model=MODEL_HUMIDIFIER_V1), From fff91210bc6374e35600142518b685c03cc3eba8 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sat, 18 Apr 2020 18:04:27 +0200 Subject: [PATCH 4/5] use dashes instead of dots in the name --- miio/discovery.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miio/discovery.py b/miio/discovery.py index 9049fe760..71b9ef1b0 100644 --- a/miio/discovery.py +++ b/miio/discovery.py @@ -112,8 +112,8 @@ "zhimi-airpurifier-mc1": AirPurifier, # mc1 "zhimi-airpurifier-mb3": AirPurifierMiot, # mb3 (3/3H) "zhimi-airpurifier-ma4": AirPurifierMiot, # ma4 (3) - "chuangmi.camera.ipc009": ChuangmiCamera, - "chuangmi.camera.ipc019": ChuangmiCamera, + "chuangmi-camera-ipc009": ChuangmiCamera, + "chuangmi-camera-ipc019": ChuangmiCamera, "chuangmi-ir-v2": ChuangmiIr, "chuangmi-remote-h102a03_": ChuangmiIr, "zhimi-humidifier-v1": partial(AirHumidifier, model=MODEL_HUMIDIFIER_V1), From 6f3fda7075a70948d00e0f540770d59bd81cec47 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Sun, 19 Apr 2020 16:07:44 +0200 Subject: [PATCH 5/5] fix rotation directions, add alarm_sound --- miio/chuangmi_camera.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/miio/chuangmi_camera.py b/miio/chuangmi_camera.py index 3eb969053..dad30403f 100644 --- a/miio/chuangmi_camera.py +++ b/miio/chuangmi_camera.py @@ -15,8 +15,8 @@ class Direction(enum.Enum): """Rotation direction.""" - Right = 1 - Left = 2 + Left = 1 + Right = 2 Up = 3 Down = 4 @@ -287,4 +287,10 @@ def night_mode_on(self): default_output=format_output("Rotating to direction '{direction.name}'"), ) def rotate(self, direction: Direction): + """Rotate camera to given direction (left, right, up, down).""" return self.send("set_motor", {"operation": direction.value}) + + @command() + def alarm(self): + """Sound a loud alarm for 10 seconds.""" + return self.send("alarm_sound")