Example #1
0
        internal void UpdateBackingObject(Light newBackingObject)
        {
            if (BackingObject.Id != newBackingObject.Id)
            {
                throw new Exception("Light ID does not match");
            }

            var oldBackingObject = BackingObject;

            BackingObject = newBackingObject;

            if (oldBackingObject.State.IsReachable != newBackingObject.State.IsReachable)
            {
                AddEvent(newBackingObject.State.IsReachable == true ? DeviceEvent.Found(this, null) : DeviceEvent.Lost(this, null));
            }

            if (Helpers.CalculatePower(oldBackingObject) != Helpers.CalculatePower(newBackingObject))
            {
                AddEvent(DeviceEvent.PowerChanged(this, null));
            }

            var oldColor = Helpers.CalculateColor(oldBackingObject);
            var newColor = Helpers.CalculateColor(newBackingObject);

            if (!oldColor.RedGreenBlue.Equals(newColor.RedGreenBlue))
            {
                AddEvent(DeviceEvent.ColorChanged(this, null));
            }
        }