Skip to content
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

yeelight: Check color mode values for emptiness #829

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions miio/yeelight.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def brightness(self) -> int:
@property
def rgb(self) -> Optional[Tuple[int, int, int]]:
"""Return color in RGB if RGB mode is active."""
if self.color_mode == YeelightMode.RGB:
return int_to_rgb(int(self.data["rgb"]))
rgb = self.data["rgb"]
if self.color_mode == YeelightMode.RGB and rgb:
return int_to_rgb(int(rgb))
return None

@property
Expand All @@ -51,15 +52,19 @@ def color_mode(self) -> YeelightMode:
@property
def hsv(self) -> Optional[Tuple[int, int, int]]:
"""Return current color in HSV if HSV mode is active."""
if self.color_mode == YeelightMode.HSV:
return self.data["hue"], self.data["sat"], self.data["bright"]
hue = self.data["hue"]
sat = self.data["sat"]
brightness = self.data["bright"]
if self.color_mode == YeelightMode.HSV and (hue or sat or brightness):
return hue, sat, brightness
return None

@property
def color_temp(self) -> Optional[int]:
"""Return current color temperature, if applicable."""
if self.color_mode == YeelightMode.ColorTemperature:
return int(self.data["ct"])
ct = self.data["ct"]
if self.color_mode == YeelightMode.ColorTemperature and ct:
return int(ct)
return None

@property
Expand Down