yeelight API

这是自动生成的API文档。把它作为公众的参考项目的API

yeelight.discover_bulbs(timeout=2)[source]

发现所有局域网内的Yeelight灯泡.

Parameters:timeout (int) – 等待回复需要多少秒。发现将总是要花这么长的时间, 因为它不知道当所有的灯泡都响应完毕时。
Returns:字典列表,包含网络中每个灯泡的IP,端口和功能。
class yeelight.Bulb(ip, port=55443, effect='smooth', duration=300, auto_on=False)[source]

YeeLight的控制类.

Parameters:
  • ip (str) – 灯泡的IP.
  • port (int) – 连接灯泡的端口号,默认55443.
  • effect (str) – 效果类型.”smooth” or “sudden”.
  • duration (int) – 效果的持续时间,以毫秒为单位.最小值为30.突然效果会忽略此值.
  • auto_on (bool) – 是否 ensure_on() 在每次操作之前调用以自动打开灯泡,如果它已关闭。这会在每条消息之前更新灯泡的属性, 每个命令会花费一个额外的消息。 如果您担心速率限制,请将其关闭并自行检查。get_properties() 或运行 ensure_on()
music_mode

Return whether the music mode is active.

Return type:bool
Returns:True if music mode is on, False otherwise.
last_properties

The last properties we’ve seen the bulb have.

This might potentially be out of date, as there’s no background listener for the bulb’s notifications. To update it, call get_properties.

get_properties()[source]

Retrieve and return the properties of the bulb.

This method also updates last_properties when it is called.

Returns:A dictionary of param: value items.
Return type:dict
ensure_on()[source]

Turn the bulb on if it is off.

bulb_type

灯泡类型

返回灯泡类型:White or Color.当尝试在属性已知之前访问时,灯泡类型是未知的。

Returns:灯泡类型.
send_command(method, params=None)[source]

请求信息并返回响应

Parameters:
  • method (str) – control method id
  • params (list) – list of params for the specified method
Returns:

the command response

name

设置或返回设备名字 :return: 返回设备名字

is_on

返回灯泡是否打开 :return:打开则是’on’,关闭侧’off’。

turn_on()[source]

打开灯泡

turn_off()[source]

关闭灯泡

toggle()[source]

反转灯泡状态.

set_rgb(red, green, blue)[source]

设置灯泡的RGB值 :param int red: 红色范围 (0-255) :param int green: 绿色范围 (0-255) :param int blue: 蓝色范围 (0-255)

set_hsv(hue, saturation)[source]

Set the bulb’s HSV value.

Parameters:
  • hue (int) – The hue to set (0-359).
  • saturation (int) – The saturation to set (0-100).
set_color_temp(degrees)[source]

设置灯泡色温

Parameters:degrees (int) – 色温范围(1700-6500).
set_adjust(action, prop)[source]

该方法用于改变智能LED的亮度、CT或颜色,在不知道当前值的情况下.

Parameters:
  • action (str) – 调整方向,可以的值是,’increase’ : 增加指定属性;100’decrease’: 减小指定属性;’circle’: 增加指定的属性,当它达到最大值后,回到最小值.
  • prop (str) – 属性调制. 可以是 “bright” 亮度调整, “ct” 色温调整, “color” 颜色调整.
set_brightness(brightness)[source]

设置灯泡亮度

Parameters:brightness (int) – 亮度范围 (1-100).
start_flow(flow)[source]

Start a flow

Parameters:flow (yeelight.Flow) – the Flow instance to start
cron_add(event_type, value)[source]

Add an event to cron.

cron_get(event_type)[source]

Retrieve an event from cron.

cron_del(event_type)[source]

Remove an event from cron.

exception yeelight.BulbException[source]

一般的 yeelight 异常类

当灯泡通知错误时会引发此异常,例如,当尝试向灯泡发出不支持的命令时。