예제 #1
0
        /// <summary>
        /// Get all access points of a specific gateway bulb.
        /// </summary>
        public static void ScanAccessPoints(this ILifxNetwork network, string ipAddress)
        {
            var command = PacketFactory.GetCommand(CommandType.GetAccessPoints);
            var gateway = new Gateway(new byte[6], ipAddress);

            ((LifxNetwork)network).SendCommand(gateway, command);
        }
        public static IBulbGroup AddGroup(this ILifxNetwork network, string name)
        {
            var n     = (LifxNetwork)network;
            var group = n.CreateGroup();

            group.Name = name;
            return(group);
        }
        private static void SetPowerState(ILifxNetwork network, IBulb bulb, bool isPowerOn)
        {
            var command = (SetPowerState)PacketFactory.GetCommand(CommandType.SetPowerState);

            command.Init(isPowerOn);

            ((LifxNetwork)network).SendCommand(bulb, command);

            ((Bulb)bulb).IsPowerOn = isPowerOn;
        }
        private static void Waveform(this ILifxNetwork network, IBulb bulb, IColor color, double cycleDurationInSeconds, float cycles, WaveformType waveform)
        {
            var command = (SetWaveForm)PacketFactory.GetCommand(CommandType.SetWaveform);
            var c       = color.ToHsv();
            var period  = (uint)cycleDurationInSeconds * 1000;

            command.Init((ushort)c.Hue, (ushort)(c.Saturation * 100), (ushort)(c.Brightness * 255), (ushort)c.Kelvin, period, cycles, 0, waveform);

            ((LifxNetwork)network).SendCommand(bulb, command);
        }
 public static void ReadBulbInfo(this ILifxNetwork network, IBulb bulb)
 {
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetInfo));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetMeshFirmware));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetMeshInfo));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetTime));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetVersion));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetWifiFirmwareState));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetWifiInfo));
 }
        public static void RenameBulb(this ILifxNetwork network, IBulb bulb, string name)
        {
            var command = (SetBulbLabel)PacketFactory.GetCommand(CommandType.SetBulbLabel);

            command.Init(name);

            ((LifxNetwork)network).SendCommand(bulb, command);

            ((Bulb)bulb).Name = name;
        }
        public static void RemoveBulbFromGroup(this ILifxNetwork network, IBulbGroup bulbGroup, IBulb bulb)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            group.Remove(bulb);

            var groups = n.Groups.Where(g => g.Contains(bulb)).ToList();

            SetGroups(n, bulb, groups);
        }
        public static void ChangeColor(this ILifxNetwork network, IBulb bulb, IColor color, double fadeTimeInSeconds)
        {
            var command = (SetLightColor)PacketFactory.GetCommand(CommandType.SetLightColor);
            var c       = color.ToHsv();

            command.Init((ushort)c.Hue, (ushort)(c.Saturation * 100), (ushort)(c.Brightness * 255), (ushort)color.Kelvin, (uint)(fadeTimeInSeconds * 1000));

            ((LifxNetwork)network).SendCommand(bulb, command);

            ((Bulb)bulb).Color = c;
        }
예제 #9
0
        public static void SetAccessPoint(this ILifxNetwork network, IGateway gateway, IAccessPoint accessPoint, string password)
        {
            var n       = (LifxNetwork)network;
            var command = (SetAccessPoint)PacketFactory.GetCommand(CommandType.SetAccessPoint);
            var ap      = (AccessPoint)accessPoint;

            command.Init(ap.Packet, password);

            n.SendCommand(gateway, command);
            n.SendCommand(gateway, PacketFactory.GetCommand(CommandType.GetWifiState));
        }
        public static void RenameGroup(this ILifxNetwork network, IBulbGroup bulbGroup, string name)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            group.Name = name;

            foreach (var bulb in group.GetBulbs())
            {
                UpdateGroupName(n, group, bulb);
            }
        }
예제 #11
0
        /// <summary>
        /// Search for gateways. If a new gateway is found, it will be scanned for new bulbs.
        /// </summary>
        public static void ScanNetwork(this ILifxNetwork network, string ipAddress)
        {
            var gateways = GatewayService.Get();

            foreach (var g in gateways)
            {
                ScanGateway(network, g);
            }

            var command = PacketFactory.GetCommand(CommandType.GetPanGateway);
            var gateway = new Gateway(new byte[6], ipAddress);

            ((LifxNetwork)network).SendCommand(gateway, command);
        }
        public static void RemoveGroup(this ILifxNetwork network, IBulbGroup bulbGroup)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            n.Remove(group);

            var allGroups = n.Groups.ToList();

            foreach (var bulb in group.GetBulbs())
            {
                var groups = allGroups.Where(g => g.Contains(bulb) && !Equals(g, group)).ToList();
                SetGroups(n, bulb, groups);
            }
        }
        public static void AddBulbToGroup(this ILifxNetwork network, IBulbGroup bulbGroup, IBulb bulb)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            if (group.Contains(bulb))
            {
                return;
            }

            group.Add(bulb);

            var groups = n.Groups.Where(g => g.Contains(bulb)).ToList();

            SetGroups(n, bulb, groups);

            UpdateGroupName(n, group, bulb);
        }
 public static void SwitchOn(this ILifxNetwork network, IBulb bulb)
 {
     SetPowerState(network, bulb, true);
 }
예제 #15
0
        /// <summary>
        /// Search for bulbs within the mesh network of the given gateway.
        /// </summary>
        public static void ScanGateway(this ILifxNetwork network, IGateway gateway)
        {
            var command = PacketFactory.GetCommand(CommandType.GetLightState);

            ((LifxNetwork)network).SendCommand(gateway, command);
        }
 public static void Pulse(this ILifxNetwork network, IBulb bulb, IColor color, double cycleDurationInSeconds, float cycles)
 {
     network.Waveform(bulb, color, cycleDurationInSeconds, cycles, WaveformType.Pulse);
 }
 public static void SwitchOff(this ILifxNetwork network, IBulb bulb)
 {
     SetPowerState(network, bulb, false);
 }