Class YeelightDevice
- Namespace
- Yeelight
- Assembly
- YeelightClient.dll
A Yeelight device on the network: who it is, what its main light is doing, and the commands that control it.
public sealed class YeelightDevice : YeelightLight, INotifyPropertyChanged
- Inheritance
-
YeelightDevice
- Implements
- Inherited Members
Remarks
A device is the object of its main light (see YeelightLight: the properties, the commands, how failures are reported), and has what concerns the device as a whole: its identity (Id, Model, FirmwareVersion, Location, Name), the methods that it supports, its connection, its timer and its music mode. Its Background is the second light of a device that has one.
You do not make a device: the YeelightClient finds it, and keeps it (and its connection) until it is told to forget it. A device is known by its Id, never by its name or its address, which can change: when the router gives a light a new address, the connection follows it.
Properties
- ActiveMode
Gets the mode of a ceiling light (daylight or moonlight), or
nullfor a device that has not reported one.
- Address
Gets the address of the device, or
nullwhen its location does not hold an IP address.
- Background
Gets the background light of the device. It always exists as an object, but only a device that has one lists its methods: look at SupportsBackgroundLight.
- FirmwareVersion
Gets the version of the firmware, which is empty until the device has said.
- Id
Gets the id of the device, for example
0x000000000015243f. This is what tells devices apart: it does not change when the name or the address of the device does.
- IsConnected
Gets whether there is a control connection to the device right now.
- IsMusicModeOn
Gets whether the device is in music mode (see StartMusicModeAsync(IPAddress?, int, CancellationToken)).
- LastSeen
Gets when anything was last heard from the device: an announcement, an answer to a search, or a message on its connection. This does not raise PropertyChanged.
- Location
Gets where the control service of the device is:
yeelight://192.168.1.239:55443.
- Model
Gets the product model, for example
color,mono,stripe,ceilingorbslamp. The lights that are known by a number or a name of their own (colora,strip6) say so here. It is empty until the device has said.
- Name
Gets the name of the device, as stored on the device with SetNameAsync(string, CancellationToken) (the Yeelight app keeps its own names in the cloud, so the two can differ). It is empty when there is none.
- NightLightBrightness
Gets the brightness of the night light mode of a ceiling light, a percentage (
0until the device has reported it).
- Port
Gets the TCP port of the control service of the device.
- SleepTimerRemaining
Gets the remaining time of the sleep timer (SetSleepTimerAsync(TimeSpan, CancellationToken)), or Zero when there is none.
- SupportedMethods
Gets the methods that the device supports, as it lists them (
set_power,set_rgb, ...). A command that is not on the list is refused by the device, and by this client before it is sent. The list is empty until the device has said.
- SupportsBackgroundLight
Gets whether the device lists
bg_set_power: it has a Background light.
- SupportsColor
Gets whether the device lists
set_rgborset_hsv: it can show colours.
- SupportsColorTemperature
Gets whether the device lists
set_ct_abx: it can show a colour temperature.
- SupportsMusicMode
Gets whether the device lists
set_music: it can be put in music mode (see StartMusicModeAsync(IPAddress?, int, CancellationToken)).
Methods
- CancelSleepTimerAsync(CancellationToken)
Stops the sleep timer.
- ConnectAsync(CancellationToken)
Makes sure that there is a connection to the device, and waits until there is. The client does this by itself for every device that it finds (see AutoConnect), and a command makes the connection when there is none.
- DisconnectAsync()
Closes the connection to the device, which frees one of its four. The next command, or ConnectAsync(CancellationToken), makes a new one.
- GetPropertiesAsync(IEnumerable<string>, CancellationToken)
Reads properties of the device with
get_prop. What the device says is taken over by this object as well.
- GetSleepTimerAsync(CancellationToken)
Gets the sleep timer of the device.
- RefreshAsync(CancellationToken)
Reads all the properties of the device (all the names that the protocol defines) and takes them over, so that the properties of this object are what the device says they are now. The client does this when a connection is made (see RefreshOnConnect), and the device reports every change after that.
- SetNameAsync(string, CancellationToken)
Gives the device a name, which is stored on the device and reported when it is found (the Yeelight app keeps its own names in the cloud, so the two can differ).
- SetSleepTimerAsync(TimeSpan, CancellationToken)
Starts a sleep timer: the light is switched off after the time. A device has one timer, and a new one replaces it. Only a light that is on accepts it.
- StartMusicModeAsync(IPAddress?, int, CancellationToken)
Puts the device in music mode: the device makes a connection to this computer, and takes the commands that are sent over it without a limit on their number (and without answering them), which is what it takes to follow music or a screen.
- Supports(string)
Gets whether the device lists a method among those that it supports.
- ToString()
Returns a string that represents the current object.
- ToggleAllAsync(CancellationToken)
Switches the main light and the background light, as they are, at the same time: on when it was off and the other way round. This is the
dev_togglemethod, which a device that has no background light may not list.