Skip to content

Commit

Permalink
Add support for gosund miot plug (cuco.plug.cp1)
Browse files Browse the repository at this point in the history
this is just a poc to show how the new api could function
  • Loading branch information
rytilahti committed Apr 18, 2020
1 parent 63d6dc0 commit 6e40d90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from miio.exceptions import DeviceError, DeviceException
from miio.fan import Fan, FanP5, FanSA1, FanV2, FanZA1, FanZA4
from miio.gateway import Gateway
from miio.gosund_plug import GosundPlug
from miio.heater import Heater
from miio.philips_bulb import PhilipsBulb, PhilipsWhiteBulb
from miio.philips_eyecare import PhilipsEyecare
Expand Down
35 changes: 35 additions & 0 deletions miio/gosund_plug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import logging
from dataclasses import dataclass, field

from .click_common import command, format_output
from .miot_device import MiotDevice

_LOGGER = logging.getLogger(__name__)


@dataclass
class GosundPlugStatus:
_max_properties = 1
state: bool = field(metadata={"siid": 2, "piid": 1})


class GosundPlug(MiotDevice):
"""Support for gosund miot plug (cuco.plug.cp1)."""

_MAPPING = GosundPlugStatus

@command()
def status(self) -> GosundPlugStatus:
"""Return current state of the plug."""

return self.get_properties_for_dataclass(GosundPlugStatus)

@command(default_output=format_output("Powering on"))
def on(self):
"""Power on."""
return self.set_property(state=True)

@command(default_output=format_output("Powering off"))
def off(self):
"""Power off."""
return self.set_property(state=False)

0 comments on commit 6e40d90

Please sign in to comment.