Skip to content

Commit

Permalink
Fix yeelight status for white-only bulbs (#1562)
Browse files Browse the repository at this point in the history
White-only bulbs (or at least yeelink.light.mono6) reports an empty
string in place of color mode.
  • Loading branch information
rytilahti committed Oct 30, 2022
1 parent 6dd94f8 commit 54a701a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions miio/integrations/light/yeelight/yeelight.py
Expand Up @@ -57,9 +57,12 @@ def rgb(self) -> Optional[Tuple[int, int, int]]:
return None

@property
def color_mode(self) -> YeelightMode:
def color_mode(self) -> Optional[YeelightMode]:
"""Return current color mode."""
return YeelightMode(int(self.data[self.get_prop_name("color_mode")]))
try:
return YeelightMode(int(self.data[self.get_prop_name("color_mode")]))
except ValueError: # white only bulbs
return None

@property
def hsv(self) -> Optional[Tuple[int, int, int]]:
Expand Down Expand Up @@ -120,7 +123,7 @@ def rgb(self) -> Optional[Tuple[int, int, int]]:
return self.lights[0].rgb

@property
def color_mode(self) -> YeelightMode:
def color_mode(self) -> Optional[YeelightMode]:
"""Return current color mode."""
return self.lights[0].color_mode

Expand Down Expand Up @@ -218,7 +221,7 @@ def cli_format(self) -> str:
s += f"{light.type.name} light\n"
s += f" Power: {light.is_on}\n"
s += f" Brightness: {light.brightness}\n"
s += f" Color mode: {light.color_mode.name}\n"
s += f" Color mode: {light.color_mode}\n"
if light.color_mode == YeelightMode.RGB:
s += f" RGB: {light.rgb}\n"
elif light.color_mode == YeelightMode.HSV:
Expand Down

0 comments on commit 54a701a

Please sign in to comment.