From 609029c43926bcdb2eacaee574339081a71145f0 Mon Sep 17 00:00:00 2001 From: Teemu R Date: Sun, 19 Apr 2020 16:10:34 +0200 Subject: [PATCH] Xiaomi camera (chuangmi.camera.ipc019): Add orientation controls and alarm (#663) * Xiaomi camera (chuangmi.camera.ipc019): Add orientation controls Related to #655 * Add a note about ipc019 * add ipc019 to discovery, closes #671 * use dashes instead of dots in the name * fix rotation directions, add alarm_sound --- miio/chuangmi_camera.py | 29 +++++++++++++++++++++++++++-- miio/discovery.py | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/miio/chuangmi_camera.py b/miio/chuangmi_camera.py index f3cd84d1d..28748152f 100644 --- a/miio/chuangmi_camera.py +++ b/miio/chuangmi_camera.py @@ -1,14 +1,26 @@ -"""Xiaomi Chuangmi camera (chuangmi.camera.ipc009) support.""" +"""Xiaomi Chuangmi camera (chuangmi.camera.ipc009, ipc019) 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.""" + + Left = 1 + Right = 2 + Up = 3 + Down = 4 + + class CameraStatus: """Container for status reports from the Xiaomi Chuangmi Camera.""" @@ -269,3 +281,16 @@ 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): + """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") diff --git a/miio/discovery.py b/miio/discovery.py index eb2c58480..4498d4a3e 100644 --- a/miio/discovery.py +++ b/miio/discovery.py @@ -112,7 +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-ipc009": ChuangmiCamera, + "chuangmi-camera-ipc019": ChuangmiCamera, "chuangmi-ir-v2": ChuangmiIr, "chuangmi-remote-h102a03_": ChuangmiIr, "zhimi-humidifier-v1": partial(AirHumidifier, model=MODEL_HUMIDIFIER_V1),