Skip to content

Commit

Permalink
Xiaomi camera (chuangmi.camera.ipc019): Add orientation controls and …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
rytilahti authored Apr 19, 2020
1 parent fab9e14 commit e30c0d1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
29 changes: 27 additions & 2 deletions miio/chuangmi_camera.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand Down Expand Up @@ -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")
3 changes: 2 additions & 1 deletion miio/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit e30c0d1

Please sign in to comment.