Skip to content

Commit

Permalink
Use setColor to set light colors
Browse files Browse the repository at this point in the history
Some lights don't handle sending setHue and setSaturation commands in
quick succession. Use a single setColor command instead (it's more
efficient anyway).

references #33
  • Loading branch information
jason0x43 committed May 12, 2020
1 parent 8ff7245 commit d2de3f7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions custom_components/hubitat/light.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Support for Hubitat lights."""

import json
from logging import getLogger
import re
from typing import Any, Dict, List, Optional, Union
Expand All @@ -13,9 +14,7 @@
CMD_ON,
CMD_SET_COLOR,
CMD_SET_COLOR_TEMP,
CMD_SET_HUE,
CMD_SET_LEVEL,
CMD_SET_SAT,
Device,
)

Expand Down Expand Up @@ -117,9 +116,14 @@ async def async_turn_on(self, **kwargs: Any) -> None:
await self.send_command(CMD_SET_LEVEL, props["level"], props["time"])
del props["time"]
elif "hue" in props:
await self.send_command(
CMD_SET_COLOR, props["hue"], props["sat"], props["level"]
arg = json.dumps(
{
"hue": props["hue"],
"saturation": props["sat"],
"level": props["level"],
}
)
await self.send_command(CMD_SET_COLOR, arg)
del props["hue"]
del props["sat"]
else:
Expand All @@ -130,8 +134,8 @@ async def async_turn_on(self, **kwargs: Any) -> None:
await self.send_command(CMD_ON)

if "hue" in props:
await self.send_command(CMD_SET_HUE, props["hue"])
await self.send_command(CMD_SET_SAT, props["sat"])
arg = json.dumps({"hue": props["hue"], "saturation": props["sat"]})
await self.send_command(CMD_SET_COLOR, arg)
del props["hue"]
del props["sat"]

Expand Down

0 comments on commit d2de3f7

Please sign in to comment.