public void ResponseCreation_Unlock_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(UNLOCK_REQUEST); SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); Assert.Null(response.Context); response.Context = new Context(); Property p = new Property(Namespaces.ALEXA_LOCKCONTROLLER, PropertyNames.LOCK_STATE, LockModes.UNLOCKED, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); 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(p); 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("Lock", response); }
public void ResponseCreation_TemperatureSensor_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(REPORT_STATE); SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); Assert.Null(response.Context); response.Context = new Context(); Setpoint s = new Setpoint(24.0, Scale.CELSIUS); Property p = new Property(Namespaces.ALEXA_TEMPERATURESENSOR, PropertyNames.TEMPERATURE, 50, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); 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(p); 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, headerName: HeaderNames.STATE_REPORT); 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("TemperatureSensor", response); }
public void ResponseCreation_SetTemperatureSingleMode_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_T_TEMPERATURE_SINGLEMODE_REQUEST); SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); Assert.Null(response.Context); response.Context = new Context(); Property p = new Property(Namespaces.ALEXA_THERMOSTATCONTROLLER, PropertyNames.TARGET_SETPOINT, new Setpoint(25.0, Scale.CELSIUS), DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); Property p3 = new Property(Namespaces.ALEXA_COLORTEMPERATURECONTROLLER, PropertyNames.THERMOSTATMODE, ThermostatModes.HEAT, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); ConnectivityPropertyValue value = new ConnectivityPropertyValue(ConnectivityModes.OK); Property p4 = 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(p3); response.Context.Properties.Add(p4); 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("SetTemperatureSingleMode", response); }
public void ResponseCreation_ColorTemperatureResponse_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(SET_COLORTEMPERATURE); SmartHomeResponse response = new SmartHomeResponse(request.Directive.Header); Assert.Null(response.Context); response.Context = new Context(); Color color = new Color(350.5, 0.7138, 0.6524); Property p = new Property(Namespaces.ALEXA_COLORTEMPERATURECONTROLLER, PropertyNames.COLOR_TEMPERATURE_IN_KELVIN, 5000, DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(), 200); 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(p); 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("ColorTemperature", response); }
public void ResponseCreation_Deactivate_Test() { SmartHomeRequest request = JsonConvert.DeserializeObject <SmartHomeRequest>(DEACTIVATE); 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, Namespaces.ALEXA_SCENECONTROLLER, HeaderNames.DEACTIVATION_STARTED); 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(SceneStartedResponsePayload), response.GetPayloadType()); SceneStartedResponsePayload p = response.Event.Payload as SceneStartedResponsePayload; Assert.Null(p.Cause); Assert.Throws <JsonSerializationException>(() => JsonConvert.SerializeObject(response)); p.Cause = new Cause(CauseTypes.APP_INTERACTION); p.Timestamp = DateTime.Parse("2017-09-27T18:30:30.45Z").ToUniversalTime(); Assert.NotNull(JsonConvert.SerializeObject(response)); Util.Util.WriteJsonToConsole("Deactivate", response); }
public static void TestBasicHealthCheckProperty(Property p, ConnectivityModes expectedMode, DateTime dateTime) { TestFunctionsV3.TestContextProperty(p, PropertyNames.CONNECTIVITY, Namespaces.ALEXA_ENDPOINTHEALTH, dateTime, 200, null); Assert.Equal(typeof(ConnectivityPropertyValue), p.Value.GetType()); ConnectivityPropertyValue conn = p.Value as ConnectivityPropertyValue; Assert.Equal(expectedMode, conn.Value); }
public void ResponseParse_CameraStream_Test() { SmartHomeResponse responseFromString = JsonConvert.DeserializeObject <SmartHomeResponse>(CAMERA_STREAM_RESPONSE); //Context check Assert.NotNull(responseFromString.Context); Assert.NotNull(responseFromString.Context.Properties); Assert.Equal(1, responseFromString.Context.Properties.Count); // Property 1 TestFunctionsV3.TestContextProperty(responseFromString.Context.Properties[0], PropertyNames.CONNECTIVITY, Namespaces.ALEXA_ENDPOINTHEALTH, DateTime.Parse("2017-09-27T18:30:30.45Z"), 200, null); Assert.Equal(responseFromString.Context.Properties[0].Value.GetType(), typeof(ConnectivityPropertyValue)); ConnectivityPropertyValue conn = responseFromString.Context.Properties[0].Value as ConnectivityPropertyValue; Assert.Equal(ConnectivityModes.OK, conn.Value); //Event Check Assert.NotNull(responseFromString.Event); Assert.Equal(typeof(Event), responseFromString.Event.GetType()); //Header Check TestFunctionsV3.TestHeaderV3(responseFromString.Event.Header, "5f8a426e-01e4-4cc9-8b79-65f8bd0fd8a4", Namespaces.ALEXA_CAMERASTREAMCONTROLLER, HeaderNames.RESPONSE); Assert.Equal("dFMb0z+PgpgdDmluhJ1LddFvSqZ/jCc8ptlAKulUj90jSqg==", responseFromString.Event.Header.CorrelationToken); //Endpoint Check Event e = responseFromString.Event as Event; TestFunctionsV3.TestEndpointV3(e.Endpoint, "endpoint-001"); TestFunctionsV3.TestBearerTokenV3(e.Endpoint.Scope, "access-token-from-Amazon"); //Payload Check Assert.Equal(typeof(ResponseCameraStreamsPayload), responseFromString.GetPayloadType()); ResponseCameraStreamsPayload payload = responseFromString.Event.Payload as ResponseCameraStreamsPayload; Assert.NotNull(payload.CameraStreams); Assert.Equal(2, payload.CameraStreams.Count); TestResponseCameraStream(payload.CameraStreams[0], "rtsp://*****:*****@link.to.video:443/feed1.mp4", DateTime.Parse("2017-09-27T20:30:30.45Z"), 30, CameraProtocols.RTSP, 1920, 1080, CameraAuthorizationTypes.BASIC, VideoCodecs.H264, AudioCodecs.AAC); TestResponseCameraStream(payload.CameraStreams[1], "rtsp://*****:*****@link.to.video:443/feed2.mp4", DateTime.Parse("2017-09-27T20:30:30.45Z"), 60, CameraProtocols.RTSP, 1280, 720, CameraAuthorizationTypes.DIGEST, VideoCodecs.MPEG2, AudioCodecs.G711); Assert.Equal("https://*****:*****@link.to.image/image.jpg", payload.ImageURI); }
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); } }