public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); double volume = Endpoint.GetValueAsync <double>("Volume").GetAwaiter().GetResult(); AlexaProperty volumeProperty = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[0], value = (int)((volume * 100)).LimitToRange(0, 100), timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(volumeProperty); bool mute = Endpoint.GetValueAsync <bool>("Mute").GetAwaiter().GetResult(); AlexaProperty muteProperty = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[1], value = mute, timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(muteProperty); return(properties); }
public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); for (int x = 0; x <= 2; x++) { Temperature temp = new Temperature(Endpoint.GetValueAsync <double>(_premiseProperties[x]).GetAwaiter().GetResult()); AlexaProperty property = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[x], value = new AlexaTemperature(Math.Round(temp.Fahrenheit, 1), "FAHRENHEIT"), timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(property); } int mode = Endpoint.GetValueAsync <int>(_premiseProperties[3]).GetAwaiter().GetResult(); AlexaProperty thermostatMode = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[3], value = ModeToString(mode), timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(thermostatMode); return(properties); }
public void ProcessControllerDirective() { try { Response.Event.payload.endpoints = PremiseServer.GetEndpointsAsync().GetAwaiter().GetResult(); if (PremiseServer.IsAsyncEventsEnabled) { Task.Run(() => { PremiseServer.Resubscribe(); }); } } catch { Response.Event.payload.endpoints.Clear(); } Response.Event.header.name = _alexaProperties[0]; string message = $"Discovery reported {Response.Event.payload.endpoints.Count} devices and scenes."; PremiseServer.HomeObject.SetValueAsync("LastRefreshed", DateTime.Now.ToString(CultureInfo.InvariantCulture)).GetAwaiter().GetResult(); PremiseServer.HomeObject.SetValueAsync("HealthDescription", message).GetAwaiter().GetResult(); PremiseServer.HomeObject.SetValueAsync("Health", "True").GetAwaiter().GetResult(); PremiseServer.WriteToWindowsApplicationEventLog(EventLogEntryType.Information, message + $" Client ip {PremiseServer.GetClientIp()}", 50); }
public void ProcessControllerDirective() { try { string valueToSend; if (Header.name == "Activate") { valueToSend = "True"; Response.Event.header.name = "ActivationStarted"; } else if (Header.name == "Deactivate") { valueToSend = "False"; Response.Event.header.name = "DeactivationStarted"; } else { ReportError(AlexaErrorTypes.INVALID_DIRECTIVE, "Operation not supported!"); return; } Endpoint.SetValueAsync(_premiseProperties[0], valueToSend).GetAwaiter().GetResult(); Response.context.properties = null; Response.Event.header.@namespace = "Alexa.SceneController"; Response.Event.payload.cause = new ChangeReportCause { type = "VOICE_INTERACTION" }; Response.Event.payload.timestamp = PremiseServer.UtcTimeStamp(); Response.Event.endpoint.cookie.path = Endpoint.GetPathAsync().GetAwaiter().GetResult(); } catch (Exception ex) { ReportError(AlexaErrorTypes.INTERNAL_ERROR, ex.Message); } }
public List <AlexaProperty> FindRelatedProperties(IPremiseObject endpoint, string currentController) { List <AlexaProperty> relatedProperties = new List <AlexaProperty>(); DiscoveryEndpoint discoveryEndpoint = PremiseServer.GetDiscoveryEndpointAsync(endpoint).GetAwaiter().GetResult(); if (discoveryEndpoint == null) { return(relatedProperties); } foreach (Capability capability in discoveryEndpoint.capabilities) { if (capability.@interface == currentController) { continue; } if (PremiseServer.Controllers.ContainsKey(capability.@interface)) { IAlexaController controller = PremiseServer.Controllers[capability.@interface]; controller.SetEndpoint(endpoint); relatedProperties.AddRange(controller.GetPropertyStates()); } } return(relatedProperties); }
public void ReportError(AlexaErrorTypes type, string message) { if (Response.GetType() != typeof(ControlResponse)) { return; } ResponseContext = null; ResponseEvent.header.name = "ErrorResponse"; ResponseEvent.payload = new AlexaErrorResponsePayload(type, message); EventLogEntryType errorType; switch (type) { case AlexaErrorTypes.INTERNAL_ERROR: errorType = EventLogEntryType.Error; break; case AlexaErrorTypes.INVALID_VALUE: case AlexaErrorTypes.VALUE_OUT_OF_RANGE: case AlexaErrorTypes.NO_SUCH_ENDPOINT: errorType = EventLogEntryType.Warning; break; default: errorType = EventLogEntryType.Information; break; } PremiseServer.NotifyErrorAsync(errorType, $"Controller Error: Controller:{RequestHeader.@namespace} ErrorType:{type} ErrorMessage:{message}", 200).GetAwaiter().GetResult(); }
public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); bool powerState = Endpoint.GetValueAsync <bool>(_premiseProperties[0]).GetAwaiter().GetResult(); AlexaProperty property = new AlexaProperty { @namespace = Namespace, value = (powerState ? "ActivationStarted" : "DeactivationStarted"), timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(property); return(properties); }
public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); bool isReachable = Endpoint.GetValueAsync <bool>(premiseProperties[0]).GetAwaiter().GetResult(); AlexaProperty property = new AlexaProperty { @namespace = @namespace, name = alexaProperties[0], timeOfSample = PremiseServer.UtcTimeStamp(), value = new AlexaEndpointHealthValue((isReachable ? "OK" : "UNREACHABLE")) }; properties.Add(property); return(properties); }
public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); double colorTemperature = Endpoint.GetValueAsync <double>(_premiseProperties[0]).GetAwaiter().GetResult(); AlexaProperty property = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[0], value = ((int)colorTemperature).LimitToRange(1000, 10000), timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(property); return(properties); }
public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); double temperature = Endpoint.GetValueAsync <double>(_premiseProperties[0]).GetAwaiter().GetResult(); Temperature temp = new Temperature(temperature); AlexaProperty property = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[0], value = new AlexaTemperature(Math.Round(temp.Fahrenheit, 1), "FAHRENHEIT"), timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(property); return(properties); }
public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); AlexaProperty volumeProperty = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[0], value = GetCurrentInput(), timeOfSample = PremiseServer.UtcTimeStamp() }; if ((string)volumeProperty.value == "") { volumeProperty.value = "NONE"; } properties.Add(volumeProperty); return(properties); }
public List <AlexaProperty> GetPropertyStates() { List <AlexaProperty> properties = new List <AlexaProperty>(); AlexaColorValue colorValue = new AlexaColorValue(); foreach (string premiseProperty in _premiseProperties) { switch (premiseProperty) { case "Hue": colorValue.hue = Math.Round(Endpoint.GetValueAsync <double>(premiseProperty).GetAwaiter().GetResult().LimitToRange(0.0, 360.0), 4); break; case "Saturation": colorValue.saturation = Math.Round(Endpoint.GetValueAsync <double>(premiseProperty).GetAwaiter().GetResult().LimitToRange(0.0, 1.0), 4); break; case "Brightness": colorValue.brightness = Math.Round(Endpoint.GetValueAsync <double>(premiseProperty).GetAwaiter().GetResult().LimitToRange(0.0, 1.0), 4); break; } } AlexaProperty property = new AlexaProperty { @namespace = Namespace, name = _alexaProperties[0], value = colorValue, timeOfSample = PremiseServer.UtcTimeStamp() }; properties.Add(property); return(properties); }
public void OnPropertyChanged(PremiseServer thisServer, PropertyChangedEventHandler handler, [CallerMemberName] string propertyName = null) { if (handler != null) { RunOnUiThread(() => handler(thisServer, new PropertyChangedEventArgs(propertyName))); } }
protected bool ValidateDirective(string[] directiveNames, string @namespace) { #region Validate request if (_header.payloadVersion != "3" || (!directiveNames.Contains(_header.name)) || (_header.@namespace != @namespace)) { ReportError(AlexaErrorTypes.INVALID_DIRECTIVE, "Invalid directive!"); return(false); } #endregion Validate request #region Connect To Premise Server try { if (PremiseServer.HomeObject == null) { ReportError(AlexaErrorTypes.ENDPOINT_UNREACHABLE, "Premise Server."); return(false); } } catch (Exception) { ReportError(AlexaErrorTypes.ENDPOINT_UNREACHABLE, "Premise Server."); return(false); } #endregion Connect To Premise Server #region VerifyAccess try { Scope testScope; // must be an endpoint-less directive (like Discovery) see if there is a scope in the payload if ((_directiveEndpoint == null) && (RequestPayloadScope != null)) { testScope = RequestPayloadScope; } else { testScope = _directiveEndpoint?.scope; } if ((testScope == null) || (testScope.type != "BearerToken") || (testScope.localAccessToken == null)) { ReportError(AlexaErrorTypes.INVALID_DIRECTIVE, "Invalid bearer token."); return(false); } if (!PremiseServer.CheckAccessTokenAsync(testScope.localAccessToken).GetAwaiter().GetResult()) { ReportError(AlexaErrorTypes.INVALID_AUTHORIZATION_CREDENTIAL, "Not authorized on local premise server."); return(false); } } catch { ReportError(AlexaErrorTypes.INTERNAL_ERROR, "Cannot find Alexa home object on local Premise server."); return(false); } #endregion VerifyAccess #region Get Premise Object try { if (_directiveEndpoint?.endpointId != null) { Guid premiseId = new Guid(_directiveEndpoint.endpointId); Endpoint = PremiseServer.HomeObject.GetObjectAsync(premiseId.ToString("B")).GetAwaiter().GetResult(); if (!Endpoint.IsValidObject()) { ReportError(AlexaErrorTypes.NO_SUCH_ENDPOINT, $"Cannot find device {_directiveEndpoint.cookie.path} ({_directiveEndpoint.endpointId}) on server."); return(false); } } } catch (Exception ex) { ReportError(AlexaErrorTypes.NO_SUCH_ENDPOINT, ex.Message); ResponseEvent.payload = new AlexaErrorResponsePayload(AlexaErrorTypes.INTERNAL_ERROR, $"Cannot find device {_directiveEndpoint.cookie.path} ({_directiveEndpoint.endpointId}) on server."); return(false); } #endregion Get Premise Object PremiseServer.InformLastContactAsync($"{_header?.name}: {RequestDirectiveEndpoint?.cookie?.path}").GetAwaiter().GetResult(); return(true); }