public IActionResult Post([FromBody] ACState state) //manually on/off ACDevice { try { try { _acStateControlService.SetCurrentState(state); } catch (CurrentACDeviceNotSetException ex) { _logger.LogError(ex, "400: Bad request"); return(BadRequest("Current ACDevice not set")); } catch (ArgumentException ex) { _logger.LogError(ex, "400: Bad request"); return(BadRequest(ex.Message)); } return(Ok()); } catch (Exception ex) { _logger.LogError(ex, "500: Internal Server Error"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
private void UpdateState(ACState state) { lock (_stateLock) { _states[state.OperationableInstanceId] = state; } }
// --- Button Functions ------------------------------------------- // private void PushSend() { // S1 = 11+8 = 2Y2 + 1Y3 SetMultiplexers(2, 3); Thread.Sleep(PauseMs); SetNeutralState(); State = ACState.On; TRACE("PushSend", "called."); }
private bool HasEmits(ACState currentState) { var emits = currentState.GetEmits(); if (emits != null && emits.MoveNext()) { return(true); } return(false); }
public void PushOff() { // S9 = 9+8 = 2Y0 + 1Y3 SetMultiplexers(0, 3); Thread.Sleep(PauseMs); SetNeutralState(); State = ACState.Off; TRACE("PushOff", "called."); }
private ACState SetServerState(ACStateType stateType, bool fireStateChange) { var state = new ACState(_client.ServerId, new[] { stateType.Id }, stateType.IconKey, null); lock (_stateLock) { _states[_client.ServerId] = state; } return(state); }
protected ACState NextState(char c, bool ignoreRootState) { ACState nextState = null; if ((m_SuccessState == null || !m_SuccessState.TryGetValue(c, out nextState)) && m_IsRootState && !ignoreRootState) { nextState = this; } return(nextState); }
private static ACState GetState(ACState currentState, char c) { ACState newCurrentState = currentState.NextState(c); while (newCurrentState == null) { currentState = currentState.GetFailingState(); newCurrentState = currentState.NextState(c); } return(newCurrentState); }
private void StoreEmits(int pos, ACState currentState, List <ACEmit> collectedEmits) { var emits = currentState.GetEmits(); if (emits != null) { while (emits.MoveNext()) { collectedEmits.Add(new ACEmit(pos - emits.Current.Length + 1, pos, emits.Current)); } } }
public ACState AddState(char c) { ACState nextState = NextStateIgnoreRootState(c); if (nextState == null) { nextState = new ACState(); if (m_SuccessState == null) { m_SuccessState = new Dictionary <char, ACState>(); } m_SuccessState.Add(c, nextState); } return(nextState); }
public void AddKeyword(string keyword, bool caseInsensitive = true) { if (string.IsNullOrEmpty(keyword)) { return; } ACState currentState = m_RootState; foreach (var c in keyword) { currentState = currentState.AddState(caseInsensitive ? char.ToLower(c) : c); } currentState.AddEmit(keyword); }
public bool ContainKeyword(string text) { ConstructFailingStates(); ACState currentState = m_RootState; foreach (var c in text) { currentState = GetState(currentState, m_ACTrieConfig.CaseInsensitive ? char.ToLower(c) : c); if (HasEmits(currentState)) { return(true); } } return(false); }
public void ParseText(string text, List <ACEmit> collectedEmits) { ConstructFailingStates(); int pos = 0; ACState currentState = m_RootState; collectedEmits.Clear(); foreach (var c in text) { currentState = GetState(currentState, m_ACTrieConfig.CaseInsensitive ? char.ToLower(c) : c); StoreEmits(pos, currentState, collectedEmits); ++pos; } collectedEmits.Sort(Interval.Compare); }
public void ConstructFailingStates() { if (m_FialingStatesConstructed) { return; } m_FialingStatesConstructed = true; Queue <ACState> queue = new Queue <ACState>(); var childStates = m_RootState.GetStates(); if (childStates != null) { foreach (var depthOneState in childStates) { depthOneState.SetFailingState(m_RootState); queue.Enqueue(depthOneState); } } while (queue.Count > 0) { ACState currentState = queue.Dequeue(); var transitions = currentState.GetTransitions(); if (transitions != null) { foreach (var transition in transitions) { ACState targetState = currentState.NextState(transition); queue.Enqueue(targetState); ACState traceFailureState = currentState.GetFailingState(); while (traceFailureState.NextState(transition) == null) { traceFailureState = traceFailureState.GetFailingState(); } ACState newFailureState = traceFailureState.NextState(transition); targetState.SetFailingState(newFailureState); targetState.AddEmits(newFailureState.GetEmits()); } } } }
public void SetFailingState(ACState failingState) { m_FailingState = failingState; }
public StateChangedEventArgs(ACState state) { State = state; }
public async Task <SkillResponse> ACRemoteHandler(SkillRequest input, ILambdaContext context) { ILambdaLogger log = context.Logger; log.LogLine($"Skill Request Object:" + JsonConvert.SerializeObject(input)); Session session = input.Session; if (session.Attributes == null) { session.Attributes = new Dictionary <string, object>(); } Type requestType = input.GetRequestType(); if (input.GetRequestType() == typeof(LaunchRequest)) { return(ResponseBuilder.Tell("AC REMOTE SKILL")); } else if (input.GetRequestType() == typeof(SessionEndedRequest)) { return(ResponseBuilder.Tell("Goodbye!")); } else if (input.GetRequestType() == typeof(IntentRequest)) { var intentRequest = (IntentRequest)input.Request; switch (intentRequest.Intent.Name) { default: case "StatusCheck": { var response = await _httpClient.GetAsync("/"); ACState status = JsonConvert.DeserializeObject <ACState>(await response.Content.ReadAsStringAsync()); var voiceResponse = $"The AC is {status.State}. It's set to {status.Temp} degrees on {status.Mode} mode."; if (status.Modifiers != Modifier.NotSet) { voiceResponse += $" The {status.Modifiers} setting is on."; } if (status.State == State.Off) { voiceResponse += " Do you want to turn it on?"; return(ResponseBuilder.Ask(voiceResponse, new Reprompt("Do you want to turn it on?"))); } else { string cardText = string.Concat(voiceResponse, $" Fan is set to {status.Fan}, swing position is set to {status.Swing} and the fan modifier is {status.Modifiers}."); return(ResponseBuilder.TellWithCard(voiceResponse, "AC Status", cardText)); } } case "TurnACOn": case "AMAZON.YesIntent": { ACState state = new ACState() { State = State.On }; var response = await _httpClient.PostAsync("/", state.AsJson()); return(response.IsSuccessStatusCode ? ResponseBuilder.Tell("Ok!") : ErrorResponse(response)); } case "TurnACOff": { ACState state = new ACState() { State = State.Off }; var response = await _httpClient.PostAsync("/", state.AsJson()); return(response.IsSuccessStatusCode ? ResponseBuilder.Tell("Ok!") : ErrorResponse(response)); } case "UpdateAction": { ACState state = new ACState(); var response = await _httpClient.PostAsync("/", state.AsJson()); return(response.IsSuccessStatusCode ? ResponseBuilder.Tell("AC Updated") : ErrorResponse(response)); } case "TempControl": { string temperatureString = intentRequest.Intent.Slots["temperature"].Value; if (!int.TryParse(temperatureString, out int temp)) { return(ResponseBuilder.Tell("Invalid temperature!")); } else if (temp < 16) { return(ResponseBuilder.Tell("That's too low")); } else if (temp > 30) { return(ResponseBuilder.Tell("That's too high")); } ACState state = new ACState() { State = State.On, Temp = temp, }; var response = await _httpClient.PostAsync("/", state.AsJson()); return(response.IsSuccessStatusCode ? ResponseBuilder.TellWithCard($"Changed to {temp}", "AC Remote", $"The temperature was set to {temp}") : ErrorResponse(response)); } case "ModeControl": { string modeStr = intentRequest.Intent.Slots["mode"].Value; Mode mode = Mode.NotSet; Modifier modifier = Modifier.NotSet; if (modeStr == "auto" || modeStr == "automatic") { mode = Mode.Auto; } else if (modeStr == "cool" || modeStr == "cold") { mode = Mode.Cold; } else if (modeStr == "hot" || modeStr == "warm" || modeStr == "heat") { mode = Mode.Hot; } else if (modeStr == "dry") { mode = Mode.Dry; } if (modeStr == "normal") { modifier = Modifier.Normal; } else if (modeStr == "quiet") { modifier = Modifier.Quiet; } else if (modeStr == "powerful") { modifier = Modifier.Powerful; } if (mode == Mode.NotSet && modifier == Modifier.NotSet) { return(ResponseBuilder.Tell("Error parsing the mode.")); } ACState state = new ACState() { Mode = mode, Modifiers = modifier }; var response = await _httpClient.PostAsync("/", state.AsJson()); if (response.IsSuccessStatusCode) { if (mode != Mode.NotSet) { return(ResponseBuilder.TellWithCard($"Mode set to {mode}", "AC Remote", $"Mode set to {mode}")); } else { return(ResponseBuilder.TellWithCard($"Mode set to {modifier}", "AC Remote", $"Mode set to {modifier}")); } } else { return(ErrorResponse(response)); } } case "SwingControl": { string swingStr = intentRequest.Intent.Slots["swing"].Value; Swing swing = Swing.NotSet; if (swingStr == "auto" || swingStr == "automatic") { swing = Swing.Auto; } else if (swingStr == "high") { swing = Swing.High; } else if (swingStr == "semi high") { swing = Swing.SemiHigh; } else if (swingStr == "medium" || swingStr == "middle") { swing = Swing.Middle; } else if (swingStr == "semi low") { swing = Swing.SemiLow; } else if (swingStr == "low") { swing = Swing.Low; } if (swing == Swing.NotSet) { return(ResponseBuilder.Tell("Invalid swing position.")); } ACState state = new ACState() { State = State.On, Swing = swing }; var response = await _httpClient.PostAsync("/", state.AsJson()); return(response.IsSuccessStatusCode ? ResponseBuilder.TellWithCard($"Swing set to {swing}", "AC Remote", $"The swing position was set to {swing}") : ErrorResponse(response)); } case "AMAZON.NoIntent": { return(ResponseBuilder.Tell("Alright!")); } case "AMAZON.CancelIntent": case "AMAZON.StopIntent": return(ResponseBuilder.Tell("Goodbye!")); } } return(ResponseBuilder.Tell("Goodbye!")); }
public ACTrie(ACTrieConfig trieConfig) { m_RootState = new ACState(true); m_ACTrieConfig = trieConfig; }