Esempio n. 1
0
        public override void CharacteristicCellReadInitialValueForCharacteristic(CharacteristicCell cell, HMCharacteristic characteristic, Action <NSObject, NSError> completion)
        {
            // This is a condition, fall back to the `EventTriggerCreator` read.
            if (Mode == CharacteristicTriggerCreatorMode.Condition)
            {
                base.CharacteristicCellReadInitialValueForCharacteristic(cell, characteristic, completion);
                return;
            }

            INSCopying value;

            if (targetValueMap.TryGetValue(characteristic, out value))
            {
                completion((NSObject)value, null);
                return;
            }

            // The user may have updated the cell value while the read was happening. We check the map one more time.
            characteristic.ReadValue(error => {
                INSCopying v;
                if (targetValueMap.TryGetValue(characteristic, out v))
                {
                    completion((NSObject)v, null);
                }
                else
                {
                    completion(characteristic.Value, error);
                }
            });
        }
Esempio n. 2
0
 // Responds to a cell change, and if the update was marked immediate, updates the characteristics.
 public void CharacteristicCellDidUpdateValueForCharacteristic(CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
 {
     pendingWrites [characteristic] = value;
     if (immediate)
     {
         UpdateCharacteristics();
     }
 }
		// Reads the characteristic's value and calls the completion with the characteristic's value.
		// If there is a pending write request on the same characteristic, the read is ignored to prevent "UI glitching".
		public void CharacteristicCellReadInitialValueForCharacteristic (CharacteristicCell cell, HMCharacteristic characteristic, Action<NSObject, NSError> completion)
		{
			characteristic.ReadValue (error => updateQueue.DispatchSync (() => {
				NSObject sentValue;
				if (sentWrites.TryGetValue (characteristic, out sentValue)) {
					completion (sentValue, null);
					return;
				}
				DispatchQueue.MainQueue.DispatchAsync (() => completion (characteristic.Value, error));
			}));
		}
Esempio n. 4
0
 // Reads the characteristic's value and calls the completion with the characteristic's value.
 // If there is a pending write request on the same characteristic, the read is ignored to prevent "UI glitching".
 public void CharacteristicCellReadInitialValueForCharacteristic(CharacteristicCell cell, HMCharacteristic characteristic, Action <NSObject, NSError> completion)
 {
     characteristic.ReadValue(error => updateQueue.DispatchSync(() => {
         NSObject sentValue;
         if (sentWrites.TryGetValue(characteristic, out sentValue))
         {
             completion(sentValue, null);
             return;
         }
         DispatchQueue.MainQueue.DispatchAsync(() => completion(characteristic.Value, error));
     }));
 }
		// Tries to use the value from the condition-value map, but falls back
		// to reading the characteristic's value from HomeKit.
		public virtual void CharacteristicCellReadInitialValueForCharacteristic (CharacteristicCell cell, HMCharacteristic characteristic, Action<NSObject, NSError> completion)
		{
			if (TryReadValue (characteristic, completion))
				return;

			characteristic.ReadValue (error => {
				// The user may have updated the cell value while the
				// read was happening. We check the map one more time.
				if (!TryReadValue (characteristic, completion))
					completion (characteristic.Value, error);
			});
		}
Esempio n. 6
0
        // If the mode is event, update the event value. Otherwise, default to super implementation
        public override void CharacteristicCellDidUpdateValueForCharacteristic(CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
        {
            switch (Mode)
            {
            case CharacteristicTriggerCreatorMode.Event:
                UpdateEventValue((INSCopying)value, characteristic);
                break;

            default:
                base.CharacteristicCellDidUpdateValueForCharacteristic(cell, value, characteristic, immediate);
                break;
            }
        }
Esempio n. 7
0
        // Tries to use the value from the condition-value map, but falls back
        // to reading the characteristic's value from HomeKit.
        public virtual void CharacteristicCellReadInitialValueForCharacteristic(CharacteristicCell cell, HMCharacteristic characteristic, Action <NSObject, NSError> completion)
        {
            if (TryReadValue(characteristic, completion))
            {
                return;
            }

            characteristic.ReadValue(error => {
                // The user may have updated the cell value while the
                // read was happening. We check the map one more time.
                if (!TryReadValue(characteristic, completion))
                {
                    completion(characteristic.Value, error);
                }
            });
        }
Esempio n. 8
0
        // Receives a callback from a `CharacteristicCell`, requesting an initial value for a given characteristic.
        // It checks to see if we have an action in this Action Set that matches the characteristic.
        // If so, calls the completion closure with the target value.
        public void CharacteristicCellReadInitialValueForCharacteristic(CharacteristicCell cell, HMCharacteristic characteristic, Action <NSObject, NSError> completion)
        {
            var value = TargetValueForCharacteristic(characteristic);

            if (value != null)
            {
                completion(value, null);
                return;
            }

            characteristic.ReadValue(error => {
                // The user may have updated the cell value while the
                // read was happening. We check the map one more time.
                var v = TargetValueForCharacteristic(characteristic);
                if (v != null)
                {
                    completion(v, null);
                }
                else
                {
                    completion(characteristic.Value, error);
                }
            });
        }
		// Responds to a cell change, and if the update was marked immediate, updates the characteristics.
		public void CharacteristicCellDidUpdateValueForCharacteristic (CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
		{
			pendingWrites [characteristic] = value;
			if (immediate)
				UpdateCharacteristics ();
		}
Esempio n. 10
0
 // Handles the value update and stores the value in the condition map.
 public virtual void CharacteristicCellDidUpdateValueForCharacteristic(CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
 {
     conditionValueMap [characteristic] = value;
 }
		// Handles the value update and stores the value in the condition map.
		public virtual void CharacteristicCellDidUpdateValueForCharacteristic (CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
		{
			conditionValueMap [characteristic] = value;
		}
		// Receives a callback from a `CharacteristicCell`, requesting an initial value for a given characteristic.
		// It checks to see if we have an action in this Action Set that matches the characteristic.
		// If so, calls the completion closure with the target value.
		public void CharacteristicCellReadInitialValueForCharacteristic (CharacteristicCell cell, HMCharacteristic characteristic, Action<NSObject, NSError> completion)
		{
			var value = TargetValueForCharacteristic (characteristic);
			if (value != null) {
				completion (value, null);
				return;
			}

			characteristic.ReadValue (error => {
				// The user may have updated the cell value while the
				// read was happening. We check the map one more time.
				var v = TargetValueForCharacteristic (characteristic);
				if (v != null)
					completion (v, null);
				else
					completion (characteristic.Value, error);
			});
		}
		// Receives a callback from a `CharacteristicCell` with a value change. Adds this value change into the targetValueMap, overwriting other value changes.
		public void CharacteristicCellDidUpdateValueForCharacteristic (CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
		{
			targetValueMap [characteristic] = value;
		}
		public override void CharacteristicCellReadInitialValueForCharacteristic (CharacteristicCell cell, HMCharacteristic characteristic, Action<NSObject, NSError> completion)
		{
			// This is a condition, fall back to the `EventTriggerCreator` read.
			if (Mode == CharacteristicTriggerCreatorMode.Condition) {
				base.CharacteristicCellReadInitialValueForCharacteristic (cell, characteristic, completion);
				return;
			}

			INSCopying value;
			if (targetValueMap.TryGetValue (characteristic, out value)) {
				completion ((NSObject)value, null);
				return;
			}

			// The user may have updated the cell value while the read was happening. We check the map one more time.
			characteristic.ReadValue (error => {
				INSCopying v;
				if (targetValueMap.TryGetValue (characteristic, out v))
					completion ((NSObject)v, null);
				else
					completion (characteristic.Value, error);
			});
		}
		// If the mode is event, update the event value. Otherwise, default to super implementation
		public override void CharacteristicCellDidUpdateValueForCharacteristic (CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
		{
			switch (Mode) {
			case CharacteristicTriggerCreatorMode.Event:
				UpdateEventValue ((INSCopying)value, characteristic);
				break;

			default:
				base.CharacteristicCellDidUpdateValueForCharacteristic (cell, value, characteristic, immediate);
				break;
			}
		}
Esempio n. 16
0
 // Receives a callback from a `CharacteristicCell` with a value change. Adds this value change into the targetValueMap, overwriting other value changes.
 public void CharacteristicCellDidUpdateValueForCharacteristic(CharacteristicCell cell, NSObject value, HMCharacteristic characteristic, bool immediate)
 {
     targetValueMap [characteristic] = value;
 }