public void RequestCreation_AdjustPercentage_Test() { SmartHomeRequest requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(ADJUST_PERCENTAGE); //Directive Check Assert.NotNull(requestFromString.Directive); //Header Check TestFunctionsV3.TestHeaderV3(requestFromString.Directive.Header, "1bd5d003-31b9-476f-ad03-71d471922820", Namespaces.ALEXA_PERCENTAGECONTROLLER, HeaderNames.ADJUST_PERCENTAGE); Assert.Equal("dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==", requestFromString.Directive.Header.CorrelationToken); //Endpoint Check TestFunctionsV3.TestEndpointV3(requestFromString.Directive.Endpoint, "endpoint-001"); TestFunctionsV3.TestBearerTokenV3(requestFromString.Directive.Endpoint.Scope, "access-token-from-skill"); //Payload Check Assert.Equal(typeof(AdjustPercentageRequestPayload), requestFromString.GetPayloadType()); AdjustPercentageRequestPayload payload = (requestFromString.Directive.Payload as AdjustPercentageRequestPayload); //Channel Assert.NotNull(payload); Assert.Equal(-20, payload.PercentageDelta); }
public void RequestCreation_SetMute_Test() { SmartHomeRequest requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_MUTE_REQUEST); //Directive Check Assert.NotNull(requestFromString.Directive); //Header Check TestFunctionsV3.TestHeaderV3(requestFromString.Directive.Header, "1bd5d003-31b9-476f-ad03-71d471922820", Namespaces.ALEXA_SPEAKER, HeaderNames.SET_MUTE); Assert.Equal("dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==", requestFromString.Directive.Header.CorrelationToken); //Endpoint Check TestFunctionsV3.TestEndpointV3(requestFromString.Directive.Endpoint, "endpoint-001"); TestFunctionsV3.TestBearerTokenV3(requestFromString.Directive.Endpoint.Scope, "access-token-from-skill"); //Payload Check Assert.Equal(typeof(SetMuteRequestPayload), requestFromString.GetPayloadType()); SetMuteRequestPayload payload = (requestFromString.Directive.Payload as SetMuteRequestPayload); //Channel Assert.NotNull(payload); Assert.Equal(true, payload.Mute); }
private async Task <object> HandleSetColor(SmartHomeRequest request, ILambdaContext context) { LambdaLogger.Log("Set color"); string token = request.Directive.Endpoint.Scope.Token; HsvColor color = request.Directive.Payload.Color; if (color == null) { LambdaLogger.Log("No color!"); throw new NullReferenceException("Color"); } LambdaLogger.Log("Got a color"); string message = string.Format("Set color HSV {0},{1},{2}", color.Hue, color.Saturation, color.Brightness); await SendDeviceStatusMessage(request, token, message); // Assume it worked... return(new ColorControlResponse { Context = new Context { Properties = new List <Property> { new ColorValueProperty { Namespace = InterfaceNamespace, Name = "color", Value = color, // TODO: Get the actual value back! TimeOfSample = DateTime.UtcNow, UncertaintyInMilliseconds = 600, } }, }, Event = ConstructReponseEvent(request.Directive, "Response"), }); }
public async Task <object> FunctionHandler(SmartHomeRequest request, ILambdaContext context) { try { LambdaLogger.Log("***********************************************" + Environment.NewLine); LambdaLogger.Log("SmartHomeSkill - Test #11" + Environment.NewLine); LambdaLogger.Log(request.ToString() + Environment.NewLine); LambdaLogger.Log("Request Namespace: " + request.Directive.Header.Namespace); LambdaLogger.Log("Request Name: " + request.Directive.Header.Name); ITinamousRestClient restClient = new RestClient(); IAlexaSmartHomeController smartHomeController = ControllerFactory.GetController(request.Directive.Header.Namespace, restClient); return(await smartHomeController.HandleAlexaRequest(request, context)); } catch (Exception ex) { LambdaLogger.Log("Exception processing function: " + ex + Environment.NewLine); throw; } }
public void RequestCreation_CameraStream_Test() { SmartHomeRequest requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(INIT_CAMERA_STREAMS_REQUEST); //Directive Check Assert.NotNull(requestFromString.Directive); //Header Check TestFunctionsV3.TestHeaderV3(requestFromString.Directive.Header, "1bd5d003-31b9-476f-ad03-71d471922820", Namespaces.ALEXA_CAMERASTREAMCONTROLLER, HeaderNames.INIT_CAMERA_STREAMS); Assert.Equal("dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==", requestFromString.Directive.Header.CorrelationToken); //Endpoint Check TestFunctionsV3.TestEndpointV3(requestFromString.Directive.Endpoint, "endpoint-001"); TestFunctionsV3.TestBearerTokenV3(requestFromString.Directive.Endpoint.Scope, "access-token-from-skill"); //Payload Check Assert.Equal(typeof(InitializeCameraRequestPayload), requestFromString.GetPayloadType()); InitializeCameraRequestPayload payload = (requestFromString.Directive.Payload as InitializeCameraRequestPayload); Assert.NotNull(payload.CameraStreams); Assert.Equal(2, payload.CameraStreams.Count); TestRequestCameraStream(payload.CameraStreams[0], CameraProtocols.RTSP, 1920, 1080, CameraAuthorizationTypes.BEARER, VideoCodecs.H264, AudioCodecs.AAC); TestRequestCameraStream(payload.CameraStreams[1], CameraProtocols.RTSP, 1280, 720, CameraAuthorizationTypes.BEARER, VideoCodecs.MPEG2, AudioCodecs.G711); }
public void RequestCreation_SetColor_Test() { SmartHomeRequest requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_COLOR_REQUEST); //Directive Check Assert.NotNull(requestFromString.Directive); //Header Check TestFunctionsV3.TestHeaderV3(requestFromString.Directive.Header, "1bd5d003-31b9-476f-ad03-71d471922820", Namespaces.ALEXA_COLORCONTROLLER, HeaderNames.SET_COLOR); Assert.Equal("dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==", requestFromString.Directive.Header.CorrelationToken); //Endpoint Check TestFunctionsV3.TestEndpointV3(requestFromString.Directive.Endpoint, "endpoint-001"); TestFunctionsV3.TestBearerTokenV3(requestFromString.Directive.Endpoint.Scope, "access-token-from-skill"); //Payload Check Assert.Equal(typeof(SetColorRequestPayload), requestFromString.GetPayloadType()); SetColorRequestPayload payload = (requestFromString.Directive.Payload as SetColorRequestPayload); Assert.NotNull(payload.Color); Assert.Equal(350.5, payload.Color.Hue); Assert.Equal(0.7138, payload.Color.Saturation); Assert.Equal(0.6524, payload.Color.Brightness); }
public Task <BaseResponse> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context) { DiscoverResponse response = new DiscoverResponse { Event = new Event { Header = new Header { MessageId = request.Directive.Header.MessageId, Namespace = "Alexa.Discovery", Name = "Discover.Response", PayloadVersion = "3" }, Payload = new EventPayload { Endpoints = GetEndpoints() } } }; return(Task.FromResult <BaseResponse>(response)); }
public void RequestCreation_Lock_Test() { SmartHomeRequest requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(LOCK_REQUEST); //Directive Check Assert.NotNull(requestFromString.Directive); //Header Check TestFunctionsV3.TestHeaderV3(requestFromString.Directive.Header, "1bd5d003-31b9-476f-ad03-71d471922820", Namespaces.ALEXA_LOCKCONTROLLER, HeaderNames.LOCK); Assert.Equal("dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==", requestFromString.Directive.Header.CorrelationToken); //Endpoint Check TestFunctionsV3.TestEndpointV3(requestFromString.Directive.Endpoint, "endpoint-001"); TestFunctionsV3.TestBearerTokenV3(requestFromString.Directive.Endpoint.Scope, "access-token-from-skill"); //Payload Check Assert.Equal(typeof(Payload), requestFromString.GetPayloadType()); /* * Assert.True(requestFromString.GetPayloadType() == typeof(TurnOnOffRequestPayload)); * TurnOnOffRequestPayload payload = requestFromString.Payload as TurnOnOffRequestPayload; * TestFunctionsV3.TestRequestApplianceAndAccessToken(payload, "accessToken", "appId", null); */ }
/// <summary> /// Add Tinamous devices tagged with "Alexa.SmartDevice" /// </summary> /// <param name="request"></param> /// <param name="response"></param> /// <returns></returns> private async Task AddDeviceEndpoints(SmartHomeRequest request, DiscoverResponse response) { // Get a list of devices filtered by the Alexa.SmartDevice Tag from Tinamous. List <DeviceDto> devices = await _devicesClient.GetDevicesAsync(request.Directive.Payload.Scope.Token); LambdaLogger.Log("Found " + devices.Count + " devices from Tinamous."); // Add each of the devices as an endpoint. foreach (DeviceDto device in devices) { LambdaLogger.Log("Adding device " + device.DisplayName); if (!device.Connected) { LambdaLogger.Log("*** Device is not connected but adding it anyway: " + device.DisplayName); } if (!device.IsReporting) { LambdaLogger.Log("*** Device is not reporting but adding it anyway: " + device.DisplayName); } // Add the base device, regardless of if it's a 2 port, 4 port or whatever outlet device. // Allows SmartHome basics such as get temperature, and turn on/off to apply to all ports. response.Event.Payload.Endpoints.Add(CreateDeviceEndpoint(device)); // If the device is tagged as a multiport device (i.e. multiple outlets) // Try and also add each of the outlets as a device, giving it a name based // on a state tag set in the devices details. if (device.Tags.Contains("MultiPort")) { LambdaLogger.Log("Adding Multi-Port Device as multiple-devices for " + device.DisplayName); response.Event.Payload.Endpoints.AddRange(CreateMultiDeviceEndpoint(device)); } } LambdaLogger.Log("Found " + response.Event.Payload.Endpoints.Count + " devices."); }
public void ResponseCreation_SetBrightness_Test() { SmartHomeRequest requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_BRIGHTNESS_REQUEST); SmartHomeResponse response = new SmartHomeResponse(requestFromString.Directive.Header); Assert.NotNull(response); Assert.Null(response.Context); response.Context = new Context(); response.Context.Properties.Add(new Property(Namespaces.ALEXA_BRIGHTNESSCONTROLLER, PropertyNames.BRIGHTNESS, 75, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200)); response.Context.Properties.Add(new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, new ConnectivityPropertyValue(ConnectivityModes.OK), DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200)); Assert.NotNull(response.Event); Event e = response.Event; TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, requestFromString.Directive.Header); Assert.Null(e.Endpoint); e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon")); Assert.NotNull(e.Payload); Assert.Equal(typeof(Payload), e.Payload.GetType()); Assert.NotNull(JsonConvert.SerializeObject(response)); Util.Util.WriteJsonToConsole("SetBrightness", response); }
public void RequestCreation_SetTemperatureTripleMode_Test() { SmartHomeRequest requestFromString = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_TRIPLEMODE_REQUEST); //Directive Check Assert.NotNull(requestFromString.Directive); //Header Check TestFunctionsV3.TestHeaderV3(requestFromString.Directive.Header, "1bd5d003-31b9-476f-ad03-71d471922820", Namespaces.ALEXA_THERMOSTATCONTROLLER, HeaderNames.SETTARGETTEMPERATURE); Assert.Equal("dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==", requestFromString.Directive.Header.CorrelationToken); //Endpoint Check TestFunctionsV3.TestEndpointV3(requestFromString.Directive.Endpoint, "endpoint-001"); TestFunctionsV3.TestBearerTokenV3(requestFromString.Directive.Endpoint.Scope, "access-token-from-skill"); //Payload Check Assert.Equal(typeof(SetTargetTemperatureRequestPayload), requestFromString.GetPayloadType()); SetTargetTemperatureRequestPayload payload = (requestFromString.Directive.Payload as SetTargetTemperatureRequestPayload); //Channel Assert.NotNull(payload); TestSetpoint(payload.TargetSetpoint, 73.0, Scale.FAHRENHEIT); TestSetpoint(payload.UpperSetpoint, 78.0, Scale.FAHRENHEIT); TestSetpoint(payload.LowerSetpoint, 68.0, Scale.FAHRENHEIT); }
public void ResponseCreation_PlaybackResponse_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(START_OVER); SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); Assert.Null(response.Context); response.Context = new Context(); ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK); Property p2 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); response.Context.Properties.Add(p2); Assert.NotNull(response.Event); Assert.Equal(typeof(Event), response.Event.GetType()); Event e = response.Event as Event; TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header); Assert.Null(e.Endpoint); e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon")); Assert.NotNull(e.Payload); Assert.Equal(typeof(Payload), response.GetPayloadType()); Assert.NotNull(JsonConvert.SerializeObject(response)); Util.Util.WriteJsonToConsole("Playback", response); }
public IActionResult Post([FromBody] SmartHomeRequest smartRequest) { if (Request.Headers.ContainsKey("Authorization")) { SmartHomeResponse resp = new SmartHomeResponse(); resp.requestId = smartRequest.requestId; resp.payload.agentUserId = "josh"; foreach (var intent in smartRequest.inputs) { if (intent.intent == "action.devices.SYNC") { resp.payload.devices = new List <Device>() { Utils.GetDevice() }; } else if (intent.intent == "action.devices.EXECUTE") { var commandInfo = intent.payload.commands.FirstOrDefault(); var executionInfo = commandInfo.execution.FirstOrDefault(); var commandsResponse = ExecutionFactory.Execute(commandInfo.devices.FirstOrDefault().id, executionInfo.command, executionInfo.parameters); resp.payload.commands = new List <CommandsResponse>() { commandsResponse }; } } return(Ok(resp)); } return(StatusCode(400)); }
public void ResponseCreation_GeneralError_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_TRIPLEMODE_REQUEST); SmartHomeResponse response = SmartHomeResponse.CreateErrorResponse(request.Directive.Header, ErrorTypes.THERMOSTAT_IS_OFF); Assert.Null(response.Context); Assert.NotNull(response.Event); Assert.Equal(typeof(Event), response.Event.GetType()); Event e = response.Event as Event; TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header, Namespaces.ALEXA_THERMOSTATCONTROLLER, HeaderNames.ERROR_RESPONSE); Assert.Null(e.Endpoint); e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon")); Assert.NotNull(e.Payload); Assert.Equal(typeof(ErrorPayload), response.GetPayloadType()); ErrorPayload p = response.Event.Payload as ErrorPayload; Assert.Equal(ErrorTypes.THERMOSTAT_IS_OFF, p.Type); Assert.Null(p.Message); Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response)); p.Message = "The thermostat is off, cannot turn on due to safety reasons"; Assert.NotNull(JsonConvert.SerializeObject(response)); Util.Util.WriteJsonToConsole("GeneralErrorThermostat", response); }
public void ResponseCreation_SetTemperatureTripleMode_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_TRIPLEMODE_REQUEST); SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); Assert.Null(response.Context); response.Context = new Context(); Property p = new Property(Namespaces.ALEXA_THERMOSTATCONTROLLER, PropertyNames.LOWER_SETPOINT, new Setpoint(68.0, Scale.FAHRENHEIT), DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); Property p2 = new Property(Namespaces.ALEXA_THERMOSTATCONTROLLER, PropertyNames.TARGET_SETPOINT, new Setpoint(72.0, Scale.FAHRENHEIT), DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); Property p3 = new Property(Namespaces.ALEXA_THERMOSTATCONTROLLER, PropertyNames.UPPER_SETPOINT, new Setpoint(76.0, Scale.FAHRENHEIT), DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); Property p4 = new Property(Namespaces.ALEXA_COLORTEMPERATURECONTROLLER, PropertyNames.THERMOSTATMODE, ThermostatModes.AUTO, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK); Property p5 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); response.Context.Properties.Add(p); response.Context.Properties.Add(p2); response.Context.Properties.Add(p3); response.Context.Properties.Add(p4); response.Context.Properties.Add(p5); Assert.NotNull(response.Event); Assert.Equal(typeof(Event), response.Event.GetType()); Event e = response.Event as Event; TestFunctionsV3.CheckResponseCreatedBaseHeader(e.Header, request.Directive.Header); Assert.Null(e.Endpoint); e.Endpoint = new Endpoint("endpoint-001", new NET.JsonObjects.Scopes.BearerToken("access-token-from-Amazon")); Assert.NotNull(e.Payload); Assert.Equal(typeof(Payload), response.GetPayloadType()); Assert.NotNull(JsonConvert.SerializeObject(response)); Util.Util.WriteJsonToConsole("SetTemperatureDualMode", response); }
public override Task <object> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context) { return(NotSupportedDirective(request.Directive)); }
public object FunctionHandler(object jsonString) { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(jsonString.ToString()); LambdaLogger.Log(JsonConvert.SerializeObject(request) + Environment.NewLine); if (request.Directive.Header.Name == HeaderNames.DISCOVERY_REQUEST) { SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); Event e = response.Event as Event; DiscoveryPayload p = e.Payload as DiscoveryPayload; foreach (var tem in domoticz.GetTemperatureDevice().result) { var setTermostato = domoticz.GetDevices().result.Where(x => Convert.ToInt32(x.ID) == Convert.ToInt32(tem.ID) && x.SubType == "SetPoint").FirstOrDefault(); if (setTermostato != null) { List <DisplayCategory> categoriest = new List <DisplayCategory>() { DisplayCategory.THERMOSTAT }; List <Capability> capabilitiest = new List <Capability>(); capabilitiest.Add(new AlexaInterface("Alexa", "3", null, null, null, null)); capabilitiest.Add(new AlexaInterface(Namespaces.ALEXA_THERMOSTATCONTROLLER, "3", new List <string>() { PropertyNames.TARGET_SETPOINT, PropertyNames.THERMOSTATMODE }, true, true)); capabilitiest.Add(new AlexaInterface(Namespaces.ALEXA_TEMPERATURESENSOR, "3", new List <string>() { PropertyNames.TEMPERATURE }, true, true)); capabilitiest.Add(new AlexaInterface(Namespaces.ALEXA_ENDPOINTHEALTH, "3", new List <string>() { PropertyNames.CONNECTIVITY }, true, true)); p.Endpoints.Add(new ResponseEndpoint(setTermostato.idx, setTermostato.HardwareName, setTermostato.Name, setTermostato.Description, cookiesTermostato, categoriest, capabilitiest)); } List <DisplayCategory> categories = new List <DisplayCategory>() { DisplayCategory.TEMPERATURE_SENSOR }; List <Capability> capabilities = new List <Capability>(); capabilities.Add(new AlexaInterface("Alexa", "3", null, null, null, null)); //capabilities.Add(new AlexaInterface(Namespaces.ALEXA_THERMOSTATCONTROLLER, "3", new List<string>() { PropertyNames.TARGET_SETPOINT, PropertyNames.THERMOSTATMODE }, true, true)); capabilities.Add(new AlexaInterface(Namespaces.ALEXA_TEMPERATURESENSOR, "3", new List <string>() { PropertyNames.TEMPERATURE }, true, true)); capabilities.Add(new AlexaInterface(Namespaces.ALEXA_ENDPOINTHEALTH, "3", new List <string>() { PropertyNames.CONNECTIVITY }, true, true)); p.Endpoints.Add(new ResponseEndpoint(tem.idx, tem.HardwareName, tem.Name, tem.Description, cookiesTemperature, categories, capabilities)); } return(response); } else if (request.Directive.Header.Name == HeaderNames.REPORT_STATE) { LambdaLogger.Log(request.Directive.Endpoint.Cookie.GetValueOrDefault("Termostato") + Environment.NewLine); SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); if (request.Directive.Endpoint.Cookie.GetValueOrDefault("Termostato") == "Termostato") { response.Context = new Context(); Setpoint temperaturaset = new Setpoint(domoticz.GetTemperatureDataDevice(request.Directive.Endpoint.EndpointID), Scale.CELSIUS); Property p = new Property(Namespaces.ALEXA_THERMOSTATCONTROLLER, PropertyNames.TARGET_SETPOINT, temperaturaset, DateTime.Now, 200); Property p3 = new Property(Namespaces.ALEXA_COLORTEMPERATURECONTROLLER, PropertyNames.THERMOSTATMODE, ThermostatModes.HEAT, DateTime.Now, 200); ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK); Property p4 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value, DateTime.Now, 200); response.Context.Properties.Add(p); response.Context.Properties.Add(p3); response.Context.Properties.Add(p4); Event e = response.Event as Event; e.Endpoint = new Endpoint(request.Directive.Endpoint.EndpointID, request.Directive.Endpoint.Scope); } else if (request.Directive.Endpoint.Cookie.GetValueOrDefault("Temperatura") == "Temperatura") { response.Context = new Context(); Setpoint s = new Setpoint(domoticz.GetTemperatureDataDevice(request.Directive.Endpoint.EndpointID), Scale.CELSIUS); Property p = new Property(Namespaces.ALEXA_TEMPERATURESENSOR, PropertyNames.TEMPERATURE, s, DateTime.Now, 200); ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK); Property p2 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value, DateTime.Now, 200); response.Context.Properties.Add(p); response.Context.Properties.Add(p2); Event e = response.Event as Event; e.Endpoint = new Endpoint(request.Directive.Endpoint.EndpointID, request.Directive.Endpoint.Scope); } return(response); } else if (request.Directive.Header.Name == HeaderNames.SETTARGETTEMPERATURE) { SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); response.Context = new Context(); LambdaLogger.Log(JsonConvert.SerializeObject(request.Directive.Payload) + Environment.NewLine); PayloadTermostato termostato = JsonConvert.DeserializeObject <PayloadTermostato>(JsonConvert.SerializeObject(request.Directive.Payload)); Property p = new Property(Namespaces.ALEXA_THERMOSTATCONTROLLER, PropertyNames.TARGET_SETPOINT, new Setpoint(termostato.targetSetpoint.value, Scale.CELSIUS), DateTime.Now, 200); Property p3 = new Property(Namespaces.ALEXA_COLORTEMPERATURECONTROLLER, PropertyNames.THERMOSTATMODE, ThermostatModes.HEAT, DateTime.Now, 200); ConnectivityPropertyValue value; if (domoticz.SetTemperatureTermostato(request.Directive.Endpoint.EndpointID, termostato.targetSetpoint.value.ToString())) { value = new ConnectivityPropertyValue(ConnectivityModes.OK); } else { value = new ConnectivityPropertyValue(ConnectivityModes.UNREACHABLE); } Property p4 = new Property(Namespaces.ALEXA_ENDPOINTHEALTH, PropertyNames.CONNECTIVITY, value, DateTime.Now, 200); response.Context.Properties.Add(p); response.Context.Properties.Add(p3); response.Context.Properties.Add(p4); Event e = response.Event as Event; e.Endpoint = new Endpoint(request.Directive.Endpoint.EndpointID, request.Directive.Endpoint.Scope); return(response); } else { return(request); } }
public override Task <object> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context) { // Activate // Deactivate throw new System.NotImplementedException(); }
public override Task <object> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context) { // CookByPreset return(NotSupportedDirective(request.Directive)); // CookingErrorResponse }
public override Task <object> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context) { throw new NotSupportedException(); }
public override Task <BaseResponse> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context) { throw new NotImplementedException(); }
public async Task DiscoverDevices_WithMultiPorts_ShouldAddMultipleDevices() { // Arrange List <DeviceDto> devices = new List <DeviceDto> { new DeviceDto { MetaTags = new List <MetaTagDto> { new MetaTagDto { Name = "PortCount", NumericValue = 4 }, new MetaTagDto { Name = "Port-1", Value = "USB Light" }, new MetaTagDto { Name = "Port-4", Value = "ThingyStick" }, }, Tags = new List <string> { "MultiPort" }, DisplayName = "Test Device", Id = "Device-Id" } }; string messageId = "MessageId1"; SmartHomeRequest request = BuildRequest(messageId); IDevicesClient devicesClient = new FakeDevicesClient(devices); DiscoveryHelper discoveryHelper = new DiscoveryHelper(devicesClient); // Act DiscoverResponse response = (DiscoverResponse)await discoveryHelper.HandleAlexaRequest(request, null); // Assert Assert.IsNotNull(response, "response nul"); Assert.IsNotNull(response.Event, "Event null"); Assert.IsNotNull(response.Event.Header, "Header null"); Assert.AreEqual("Alexa.Discovery", response.Event.Header.Namespace, "Namespace"); Assert.AreEqual("Discover.Response", response.Event.Header.Name, "Name"); Assert.AreEqual("3", response.Event.Header.PayloadVersion, "PayloadVersion"); Assert.AreEqual(messageId, response.Event.Header.MessageId, "MessageId"); var endpoints = response.Event.Payload.Endpoints; Assert.IsNotNull(endpoints, "response.Event.Payload.Endpoints null"); // Expect 2 sub-devices as only 2 are names. // plus one parent device. Assert.AreEqual(3, endpoints.Count, "response.Event.Payload.Endpoints null"); Assert.AreEqual("Test Device", endpoints[0].FriendlyName, "endpoints[0].FriendlyName"); Assert.AreEqual("Device-Id", endpoints[0].EndpointId, "endpoints[0].EndpointId"); Assert.AreEqual("USB Light", endpoints[1].FriendlyName, "endpoints[1].FriendlyName"); Assert.AreEqual("Device-Id#port-1#", endpoints[1].EndpointId, "endpoints[1].EndpointId"); Assert.AreEqual("ThingyStick", endpoints[2].FriendlyName, "endpoints[2].FriendlyName"); Assert.AreEqual("Device-Id#port-4#", endpoints[2].EndpointId, "endpoints[2].EndpointId"); }
public abstract Task <BaseResponse> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context);
public abstract Task <object> HandleAlexaRequest(SmartHomeRequest request, ILambdaContext context);