-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of the water purifier support (#67)
* First draft of the water purifier support. * Small glitch fixed. * Missing import added. * Unused import removed. * README.m updated.
- Loading branch information
Showing
4 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
from typing import Any, Dict | ||
from collections import defaultdict | ||
from .device import Device | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class WaterPurifier(Device): | ||
"""Main class representing the waiter purifier.""" | ||
|
||
def status(self): | ||
"""Retrieve properties.""" | ||
|
||
properties = ['power'] | ||
|
||
values = self.send( | ||
"get_prop", | ||
properties | ||
) | ||
|
||
properties_count = len(properties) | ||
values_count = len(values) | ||
if properties_count != values_count: | ||
_LOGGER.debug( | ||
"Count (%s) of requested properties does not match the " | ||
"count (%s) of received values.", | ||
properties_count, values_count) | ||
|
||
return WaterPurifierStatus( | ||
defaultdict(lambda: None, zip(properties, values))) | ||
|
||
def on(self): | ||
"""Power on.""" | ||
return self.send("set_power", ["on"]) | ||
|
||
def off(self): | ||
"""Power off.""" | ||
return self.send("set_power", ["off"]) | ||
|
||
|
||
class WaterPurifierStatus: | ||
"""Container for status reports from the water purifier.""" | ||
|
||
def __init__(self, data: Dict[str, Any]) -> None: | ||
self.data = data | ||
|
||
@property | ||
def power(self) -> str: | ||
return self.data["power"] | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
return self.power == "on" | ||
|
||
def __str__(self) -> str: | ||
return "<WaterPurifierStatus power=%s>" % self.power |