Beispiel #1
0
        private void HandleWifiStatePacket(IBulb bulb, AnswerPacketBase packet)
        {
            var wifiState = packet as WifiState;

            if (wifiState == null)
            {
                return;
            }

            if (wifiState.InterfaceType == Interface.Station && wifiState.WifiStatus == WifiStatus.Connected)
            {
                IsBulbSuccessfullyConnectedToWifi = true;
            }
        }
Beispiel #2
0
        private void HandleAccessPoint(AnswerPacketBase packet)
        {
            var accessPoint = packet as Packets.AccessPoint;

            if (accessPoint == null)
            {
                return;
            }

            if (!_accessPoints.ContainsKey(accessPoint.SsidName))
            {
                lock (_accessPointCollectionLock)
                {
                    if (!_accessPoints.ContainsKey(accessPoint.SsidName))
                    {
                        _accessPoints.Add(accessPoint.SsidName, new AccessPoint(accessPoint));
                    }
                }
            }
        }
Beispiel #3
0
        private Bulb HandleBulbPacket(IGateway gateway, AnswerPacketBase packet)
        {
            Bulb bulb;

            if (!_bulbs.TryGetValue(packet.TargetMacAddress, out bulb))
            {
                lock (_bulbCollectionLock)
                {
                    if (!_bulbs.TryGetValue(packet.TargetMacAddress, out bulb))
                    {
                        bulb = new Bulb(packet.TargetMacAddress, gateway);
                        _bulbs.Add(bulb.Mac, bulb);
                        OnBulbCollectionChanged();
                    }
                }
            }

            packet.Apply(bulb);
            return(bulb);
        }
Beispiel #4
0
        private void HandleGroupNamePacket(AnswerPacketBase packet)
        {
            var tagLabels = packet as TagLabels;

            if (tagLabels != null)
            {
                var name = tagLabels.Label.ToUtf8String();
                if (tagLabels.Tags == 0 || string.IsNullOrEmpty(name) || !tagLabels.Tags.IsSingleGroup())
                {
                    return;
                }

                BulbGroup g;
                if (!_groups.TryGetValue(tagLabels.Tags, out g) || string.Equals(g.Name, name, StringComparison.Ordinal))
                {
                    return;
                }

                g.Name = name;
            }
        }
Beispiel #5
0
        private void HandleBulbGroupsPacket(IBulb bulb, AnswerPacketBase packet)
        {
            var lightStatus = packet as LightStatus;
            var tags        = packet as Tags;

            if (tags != null || lightStatus != null)
            {
                var bitmask = lightStatus != null ? lightStatus.Bitmask : tags.Bitmask;

                var groupBitmasks = bitmask.GetGroupTags().ToList();

                foreach (var groupBitmask in groupBitmasks)
                {
                    BulbGroup group;
                    if (!_groups.TryGetValue(groupBitmask, out group))
                    {
                        lock (_groupCollectionLock)
                        {
                            if (!_groups.TryGetValue(groupBitmask, out group))
                            {
                                group = CreateGroup(groupBitmask);
                            }
                        }
                    }

                    group.Add(bulb);

                    if (string.IsNullOrEmpty(group.Name))
                    {
                        var getTagLabels = (GetTagLabels)PacketFactory.GetCommand(CommandType.GetTagLabels);
                        getTagLabels.Init(groupBitmask);
                        SendCommand(bulb, getTagLabels);
                    }
                }
            }
        }