private void UpdateState(MotionDetectionStateValue state) { if (state == _motionDetectionState) { return; } if (state == MotionDetectionStateValue.MotionDetected && !Settings.IsEnabled) { return; } var oldState = GetState(); _motionDetectionState = state; OnStateChanged(oldState); if (state == MotionDetectionStateValue.MotionDetected) { ((Trigger)MotionDetectedTrigger).Execute(); } else if (state == MotionDetectionStateValue.Idle) { ((Trigger)MotionDetectionCompletedTrigger).Execute(); } }
private void UpdateState(object sender, MotionDetectorAdapterStateChangedEventArgs e) { var state = e.State == AdapterMotionDetectionState.MotionDetected ? MotionDetectionStateValue.MotionDetected : MotionDetectionStateValue.Idle; lock (_syncRoot) { if (state == _motionDetectionState) { return; } if (state == MotionDetectionStateValue.MotionDetected && !Settings.IsEnabled) { return; } var oldState = GetState(); _motionDetectionState = state; OnStateChanged(oldState); if (state == MotionDetectionStateValue.MotionDetected) { _messageBroker.Publish(Id, new MotionDetectedEvent()); } else if (state == MotionDetectionStateValue.Idle) { _messageBroker.Publish(Id, new MotionDetectionCompletedEvent()); } } }
public static bool TryGetMotionDetectionState(this IComponent component, out MotionDetectionStateValue value) { if (component == null) { throw new ArgumentNullException(nameof(component)); } return(TryGetStateValue <MotionDetectionState, MotionDetectionStateValue>(component, s => s.Value, out value)); }