-
-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Device support of the Xioami Philips Smart LED Ball Lamp #94
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
import inspect | ||
import codecs | ||
from . import (Device, Vacuum, Plug, PlugV1, Strip, AirPurifier, Ceil, | ||
PhilipsEyecare, ChuangmiIr, AirHumidifier, WaterPurifier, | ||
WifiSpeaker, Yeelight) | ||
PhilipsBulb, PhilipsEyecare, ChuangmiIr, AirHumidifier, | ||
WaterPurifier, WifiSpeaker, Yeelight) | ||
from typing import Union, Callable, Dict, Optional # noqa: F401 | ||
|
||
|
||
|
@@ -29,7 +29,7 @@ | |
"zhimi-humidifier-v1": AirHumidifier, | ||
"yunmi-waterpuri-v2": WaterPurifier, | ||
# It looks like philips devices cannot be discovered via mdns | ||
"philips-light-bulb": Ceil, | ||
"philips-light-bulb": PhilipsBulb, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. undefined name 'PhilipsBulb' |
||
"philips-light-ceil": Ceil, | ||
"philips-light-sread1": PhilipsEyecare, | ||
"xiaomi-wifispeaker-v1": WifiSpeaker, # name needs to be checked | ||
|
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,92 @@ | ||
import logging | ||
from .device import Device | ||
from typing import Any, Dict | ||
from collections import defaultdict | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class PhilipsBulbStatus: | ||
"""Container for status reports from Xiaomi Philips LED Ceiling Lamp""" | ||
|
||
def __init__(self, data: Dict[str, Any]) -> None: | ||
# ['power': 'on', 'bright': 85, 'cct': 9, 'snm': 0, 'dv': 0] | ||
self.data = data | ||
|
||
@property | ||
def power(self) -> str: | ||
return self.data["power"] | ||
|
||
@property | ||
def is_on(self) -> bool: | ||
return self.power == "on" | ||
|
||
@property | ||
def brightness(self) -> int: | ||
return self.data["bright"] | ||
|
||
@property | ||
def color_temperature(self) -> int: | ||
return self.data["cct"] | ||
|
||
@property | ||
def scene(self) -> int: | ||
return self.data["snm"] | ||
|
||
@property | ||
def delay_off_countdown(self) -> int: | ||
return self.data["dv"] | ||
|
||
def __str__(self) -> str: | ||
s = "<PhilipsBulbStatus power=%s, brightness=%s, " \ | ||
"color_temperature=%s, scene=%s, delay_off_countdown=%s>" % \ | ||
(self.power, self.brightness, | ||
self.color_temperature, self.scene, self.delay_off_countdown) | ||
return s | ||
|
||
|
||
class PhilipsBulb(Device): | ||
"""Main class representing Xiaomi Philips LED Ball Lamp.""" | ||
|
||
def on(self): | ||
"""Power on.""" | ||
return self.send("set_power", ["on"]) | ||
|
||
def off(self): | ||
"""Power off.""" | ||
return self.send("set_power", ["off"]) | ||
|
||
def set_brightness(self, level: int): | ||
"""Set brightness level.""" | ||
return self.send("set_bright", [level]) | ||
|
||
def set_color_temperature(self, level: int): | ||
"""Set Correlated Color Temperature.""" | ||
return self.send("set_cct", [level]) | ||
|
||
def delay_off(self, seconds: int): | ||
"""Set delay off seconds.""" | ||
return self.send("delay_off", [seconds]) | ||
|
||
def set_scene(self, num: int): | ||
"""Set scene number.""" | ||
return self.send("apply_fixed_scene", [num]) | ||
|
||
def status(self) -> PhilipsBulbStatus: | ||
"""Retrieve properties.""" | ||
properties = ['power', 'bright', 'cct', 'snm', 'dv', ] | ||
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 PhilipsBulbStatus( | ||
defaultdict(lambda: None, zip(properties, values))) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined name 'PhilipsBulb'