Exemplo n.º 1
0
        public void OnPresenceStarted(object?sender, HassEventArgs args)
        {
            if (_configurator.LuxAboveLimit)
            {
                return;
            }

            DisposeTimer(args);
            TurnOnControlEntities();
            _app.LogEventHandled(args);
        }
Exemplo n.º 2
0
        public void OnHouseModeChanged(object?sender, HassEventArgs args)
        {
            if (!IsActive)
            {
                _configurator.Configure(_app); // Configure so entities are ready for next time
                return;
            }

            TurnOffControlEntities();
            _configurator.Configure(_app);
            TurnOnControlEntities();
            _app.LogEventHandled(args);
        }
Exemplo n.º 3
0
        public void OnPresenceStopped(object?sender, HassEventArgs args)
        {
            if (IsActive)
            {
                _app.LogInformation("{CorrelationId} - Presence Active: {RoomName} no timer set. Active sensors {Sensors}", args.CorrelationId, args.RoomName, string.Join(", ", _configurator.ActivePresenceSensors.Select(p => p.EntityId)));
                _app.LogEventHandled(args);
                return;
            }

            SetTimer(TimeSpan.FromSeconds(_configurator.TimeoutSeconds), () =>
            {
                TurnOffControlEntities();
                _app.LogEventHandled(args);
            }, args);
        }
Exemplo n.º 4
0
 private void DisposeTimer(HassEventArgs args)
 {
     _timer?.Dispose();
     _timer = null;
     _app.LogInformation("{CorrelationId} - Timer disposed: {RoomName}", args.CorrelationId, args.RoomName);
 }
Exemplo n.º 5
0
 private void SetTimer(TimeSpan ts, Action action, HassEventArgs args)
 {
     DisposeTimer(args);
     _timer = _app.RunIn(ts, action);
     _app.LogInformation("{CorrelationId} - Timer set: {RoomName} for {Timeout}", args.CorrelationId, args.RoomName, ts);
 }
Exemplo n.º 6
0
 public static void LogEventHandled(this INetDaemonRxApp app, HassEventArgs args)
 {
     app.LogInformation("{CorrelationId} - Event Handled: {EventType}", args.CorrelationId, args.EventType);
 }