Exemple #1
0
        private void OnNightModeChanged(object?sender, HassEventArgs args)
        {
            hassEventArgs = args;
            if (IsDisabled() || RoomIs(RoomState.Idle))
            {
                return;
            }
            _eventEntity = args.EntityId;

            _app.Delay(TimeSpan.FromSeconds(1));
            if (IsNightTime)
            {
                foreach (var entityId in _controlEntityIds.Except(_nightControlEntityIds))
                {
                    _app.Entity(entityId).TurnOff();
                }
                foreach (var entityId in _nightControlEntityIds)
                {
                    _app.Entity(entityId).TurnOn();
                }
            }
            else
            {
                foreach (var entityId in _nightControlEntityIds.Except(_controlEntityIds))
                {
                    _app.Entity(entityId).TurnOff();
                }
                foreach (var entityId in _controlEntityIds)
                {
                    _app.Entity(entityId).TurnOn();
                }
            }
        }
Exemple #2
0
 public void Initialize()
 {
     hassEventArgs = new HassEventArgs(_roomConfig.Name, "RoomInit");
     try
     {
         LogInfoJson(hassEventArgs, "Start", data: new
         {
             _roomConfig,
             Scheduler?.Now,
             _tracePrefix,
             _normalTimeout   = _normalTimeout.TotalSeconds,
             _nightTimeout    = _nightTimeout.TotalSeconds,
             _overrideTimeout = _overrideTimeout.TotalSeconds,
             _presenceEntityIds,
             _controlEntityIds,
             _nightControlEntityIds,
             _keepAliveEntityIds,
             NdUserId
         });
         VerifyConfig(_roomConfig);
         SetupEnabledSwitchEntity();
         IsDisabled();
         SetupSubscriptions();
         StartGuardDog();
         LogTrace("Initialize Complete");
     }
     catch (Exception e)
     {
         _app.LogError(e, "Error in Initialize");
         throw;
     }
 }
Exemple #3
0
 private void OnGuardDog(object?sender, HassEventArgs args)
 {
     hassEventArgs = args;
     if (IsDisabled() || Timer != null && (Presence || RoomIs(RoomState.Override)))
     {
         return;
     }
     _eventEntity = args.EntityId;
     SetRoomState(RoomState.Override);
 }
Exemple #4
0
 private void OnPresence(object?sender, HassEventArgs args)
 {
     hassEventArgs = args;
     if (IsDisabled() || !Presence || !LuxBelowThreshold() || !ConditionMatched() || RoomIs(RoomState.Override))
     {
         return;
     }
     _eventEntity = hassEventArgs.EntityId;
     SetRoomState(RoomState.Active);
 }
Exemple #5
0
 private void OnManualTurnOff(object?sender, HassEventArgs args)
 {
     hassEventArgs = args;
     if (IsDisabled())
     {
         return;
     }
     _eventEntity = args.EntityId;
     SetRoomState(RoomState.Idle);
 }
Exemple #6
0
        private static object NewLogMessage(HassEventArgs args, string method, long line, string message, object?data)
        {
            var logMessageData = new
            {
                TimeStamp = $"{DateTime.Now:O}".Replace("\u002B", "Z"),
                args.RoomName,
                args.EventName,
                args.CorrelationId,
                method,
                line,
                message,
                data
            };

            return(logMessageData);
        }
Exemple #7
0
 private void OnTimeoutEvent(object?sender, HassEventArgs args)
 {
     hassEventArgs = args;
     if (IsDisabled())
     {
         return;
     }
     if (Presence && LuxBelowThreshold())
     {
         _eventEntity = args.EntityId;
         SetRoomState(RoomState.Active);
     }
     else
     {
         _eventEntity = "";
         SetRoomState(RoomState.Idle);
     }
 }
Exemple #8
0
 private void OnRandomEntityChanged(object?sender, HassEventArgs args)
 {
     hassEventArgs = args;
     SetRoomState(_roomConfig.RandomStates.Contains(args.NewState) ? RoomState.RandomWait : RoomState.Idle);
 }
Exemple #9
0
        private void LogWarnJson(HassEventArgs args, string message = "", [CallerMemberName] string method = "", [CallerLineNumber] long line = 0, object?data = null)
        {
            var logMessageData = NewLogMessage(args, method, line, message, data);

            Log.Logger.Warning(ToJson(logMessageData));
        }