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(); } } }
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; } }
private void OnGuardDog(object?sender, HassEventArgs args) { hassEventArgs = args; if (IsDisabled() || Timer != null && (Presence || RoomIs(RoomState.Override))) { return; } _eventEntity = args.EntityId; SetRoomState(RoomState.Override); }
private void OnPresence(object?sender, HassEventArgs args) { hassEventArgs = args; if (IsDisabled() || !Presence || !LuxBelowThreshold() || !ConditionMatched() || RoomIs(RoomState.Override)) { return; } _eventEntity = hassEventArgs.EntityId; SetRoomState(RoomState.Active); }
private void OnManualTurnOff(object?sender, HassEventArgs args) { hassEventArgs = args; if (IsDisabled()) { return; } _eventEntity = args.EntityId; SetRoomState(RoomState.Idle); }
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); }
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); } }
private void OnRandomEntityChanged(object?sender, HassEventArgs args) { hassEventArgs = args; SetRoomState(_roomConfig.RandomStates.Contains(args.NewState) ? RoomState.RandomWait : RoomState.Idle); }
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)); }