Skip to content

Commit

Permalink
- Added RGB to Yeelight device
Browse files Browse the repository at this point in the history
 - Added current power state to device overview, so it's easier to find the correct device
  • Loading branch information
RonSijm committed Jan 6, 2023
1 parent fedbe4d commit 5173078
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions RonSijm.ButtFish/Models/YeelightDevice.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
using YeelightAPI;
using RonSijm.ButtFish.Encoders;
using YeelightAPI;

namespace RonSijm.ButtFish.Models;

public class YeelightDevice : IDeviceAbstraction
{
public override string ToString()
{
return _selectedDevice == null ? "Inner device null" : _selectedDevice.Hostname;
if (_selectedDevice == null)
{
return "Inner device null";
}

var displayName = _selectedDevice.Hostname;
var stateResult = _selectedDevice.Properties.TryGetValue("power", out var state);

if (stateResult)
{
if (state.ToString() == "on")
{
displayName += " - Light is On";
}
}

return displayName;
}

private readonly Device _selectedDevice;
Expand All @@ -23,6 +40,24 @@ public async Task SendDuration(int time)
await _selectedDevice.Connect();
}

// Not sure how non-RGB devices behave when sending this command
// So putting it in a try/catch
try
{
if (time == TimeUnitConfig.DotTime)
{
await _selectedDevice.SetRGBColor(255, 0, 0);
}
else
{
await _selectedDevice.SetRGBColor(0, 255, 0);
}
}
catch (Exception)
{
// Do nothing
}

await _selectedDevice.SetBrightness(100, 1);
await Task.Delay(time);
await _selectedDevice.SetBrightness(1, 1);
Expand Down

0 comments on commit 5173078

Please sign in to comment.