예제 #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);
                }
            });
        }
		// 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));
			}));
		}
예제 #3
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));
     }));
 }
예제 #4
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);
                }
            });
        }
예제 #5
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);
                }
            });
        }
		// 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);
			});
		}
예제 #7
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);
			});
		}
		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);
			});
		}