Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_power_mode3(self):
self.bulb.set_power_mode(enums.PowerMode.LAST)
self.assertEqual(self.socket.sent["method"], "set_power")
self.assertEqual(self.socket.sent["params"], ["on", "smooth", 300])
"set_hsv": ["hue", "sat"],
"set_bright": ["bright"],
"set_power": ["power"],
}
# Handle toggling separately, as it depends on a previous power state.
if method == "toggle":
self._last_properties["power"] = "on" if self._last_properties["power"] == "off" else "off"
elif method in action_property_map:
set_prop = action_property_map[method]
update_props = {set_prop[prop]: params[prop] for prop in range(len(set_prop))}
_LOGGER.debug("Music mode cache update: %s", update_props)
self._last_properties.update(update_props)
# Add the effect parameters.
params += [effect, duration]
# Add power_mode parameter.
if method == "set_power" and params[0] == "on" and power_mode.value != PowerMode.LAST:
params += [power_mode.value]
result = self.send_command(method, params).get("result", [])
if result:
return result[0]
def __init__(
self, ip, port=55443, effect="smooth", duration=300, auto_on=False, power_mode=PowerMode.LAST, model=None
):
"""
The main controller class of a physical YeeLight bulb.
:param str ip: The IP of the bulb.
:param int port: The port to connect to on the bulb.
:param str effect: The type of effect. Can be "smooth" or "sudden".
:param int duration: The duration of the effect, in milliseconds. The
minimum is 30. This is ignored for sudden effects.
:param bool auto_on: Whether to call :py:meth:`ensure_on()
` to turn the bulb on
automatically before each operation, if it is off.
This renews the properties of the bulb before each
message, costing you one extra message per command.
Turn this off and do your own checking with
:py:meth:`get_properties()
def _turn_on_power_mode(self):
return PowerMode.LAST
"set_hsv": ["hue", "sat"],
"set_bright": ["bright"],
"set_power": ["power"],
}
# Handle toggling separately, as it depends on a previous power state.
if method == "toggle":
self._last_properties["power"] = "on" if self._last_properties["power"] == "off" else "off"
elif method in action_property_map:
set_prop = action_property_map[method]
update_props = {set_prop[prop]: params[prop] for prop in range(len(set_prop))}
_LOGGER.debug("Music mode cache update: %s", update_props)
self._last_properties.update(update_props)
# Add the effect parameters.
params += [effect, duration]
# Add power_mode parameter.
if method == "set_power" and params[0] == "on" and power_mode.value != PowerMode.LAST:
params += [power_mode.value]
result = self.send_command(method, params).get("result", [])
if result:
return result[0]
def __init__(
self, ip, port=55443, effect="smooth", duration=300, auto_on=False, power_mode=PowerMode.LAST, model=None
):
"""
The main controller class of a physical YeeLight bulb.
:param str ip: The IP of the bulb.
:param int port: The port to connect to on the bulb.
:param str effect: The type of effect. Can be "smooth" or "sudden".
:param int duration: The duration of the effect, in milliseconds. The
minimum is 30. This is ignored for sudden effects.
:param bool auto_on: Whether to call :py:meth:`ensure_on()
` to turn the bulb on
automatically before each operation, if it is off.
This renews the properties of the bulb before each
message, costing you one extra message per command.
Turn this off and do your own checking with
:py:meth:`get_properties()