public async Task <IActionResult> ReportState(Guid requestId, [FromBody] ReportStateDirective directive) { var resp = new ContextResponse { Context = new EndpointContext { Properties = new List <ContextProperty> { new ContextProperty { Name = "temperature", Namespace = "Alexa.TemperatureSensor", TimeOfSample = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ff'Z'"), UncertaintyInMilliseconds = 500, Value = new EndpointValue { Value = await _master.GetCurrentTemp(), Scale = "FAHRENHEIT" } }, new ContextProperty { Name = "lowerSetpoint", Namespace = "Alexa.ThermostatController", TimeOfSample = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ff'Z'"), UncertaintyInMilliseconds = 500, Value = new EndpointValue { Value = 98, Scale = "FAHRENHEIT" } }, new ContextProperty { Name = "targetSepoint", Namespace = "Alexa.ThermostatController", TimeOfSample = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'ff'Z'"), UncertaintyInMilliseconds = 500, Value = new EndpointValue { Value = 102, Scale = "FAHRENHEIT" } } } }, Event = new ReportStateEvent { Header = new Header { MessageId = directive.Directive.Header.MessageId, Name = "StateReport", PayloadVersion = "3", Namespace = "Alexa", CorrelationToken = directive.Directive.Header.CorrelationToken }, Endpoint = new DirectiveEndpoint { Scope = directive.Directive.Endpoint.Scope, EndpointId = "smartwater01" }, Payload = new EmptyObject() } }; return(Ok(resp)); }
static void Main(string[] args) { string token = ConfigurationSettings.AppSettings["Token"]; OrionClient.OrionConfig config = new OrionClient.OrionConfig() { Token = token, }; OrionClient client = new OrionClient(config); OrionVersion version = client.GetOrionVersionAsync().Result; Debug.WriteLine(version.Orion.Version); ContextUpdate create = new ContextUpdate() { UpdateAction = UpdateActionTypes.APPEND, ContextElements = new List <ContextElement>() { new ContextElement() { Type = "User", IsPattern = false, Id = "76afe5ed-a2b1-49f8-ba53-92eef732d265", Attributes = new List <SMARTFI.OrionContextBroker.Client.Models.ContextAttribute>() { new SMARTFI.OrionContextBroker.Client.Models.ContextAttribute() { Name = "userlocation", Type = "string", Value = "23", } } }, } }; ContextResponses createResponses = client.UpdateContextAsync(create).Result; Debug.WriteLine(createResponses.Responses.First().StatusCode.ReasonPhrase); ContextUpdate update = new ContextUpdate() { UpdateAction = UpdateActionTypes.UPDATE, ContextElements = new List <ContextElement>() { new ContextElement() { Type = "Room", IsPattern = false, Id = "Room-S-123", Attributes = new List <SMARTFI.OrionContextBroker.Client.Models.ContextAttribute>() { new SMARTFI.OrionContextBroker.Client.Models.ContextAttribute() { Name = "temperature", Type = "float", Value = "230", Metadata = new List <ContextAttributeMetadata>() { new ContextAttributeMetadata() { Name = "AcquisitionKey", Type = "string", Value = "user.app.iphone" } } } } }, } }; StatusCode setAttributeResult = client.SetAttributeValueForEntityAsync("Room-S-123", "temperature", new Random().Next(-30, 45).ToString()).Result; ContextResponses updateResponses = client.UpdateContextAsync(update).Result; Debug.WriteLine(updateResponses.Responses.First().StatusCode.ReasonPhrase); ContextQuery query = new ContextQuery() { Entities = new List <ContextQueryEntity>() { new ContextQueryEntity() { Type = "Room", IsPattern = true, Id = "Room.*", }, }, }; ContextResponses queryResponses = client.QueryAsync(query).Result; foreach (var item in queryResponses.Responses) { Debug.WriteLine(item.ContextElement.Id); } ContextQuery query2 = new ContextQuery() { Entities = new List <ContextQueryEntity>() { new ContextQueryEntity() { Type = "Room", IsPattern = true, Id = "Room.*", }, }, Attributes = new List <string>() { "temperature", } }; ContextResponses queryResponses2 = client.QueryAsync(query2).Result; foreach (var item in queryResponses2.Responses) { Debug.WriteLine(item.ContextElement.Id); } ContextSubscription subscription = new ContextSubscription() { Entities = new List <ContextQueryEntity>() { new ContextQueryEntity() { Type = "Room", IsPattern = true, Id = "Room.*" }, }, Attributes = new List <string>() { "temperature" }, Reference = "http://smarthome.cloudapp.net/api/UserContext/Broker", Duration = SubscriptionDurations.OneMonth, NotifyConditions = new List <NotifyCondition>() { new NotifyCondition() { Type = NotifyConditionTypes.ONCHANGE, ConditionValues = new List <string>() { "temperature" } } }, Throttling = SubscriptionThrottlingTypes.PT5S }; ContextSubscriptionResponse subscriptionResponse = client.SubscribeAsync(subscription).Result; Debug.WriteLine(subscriptionResponse.SubscribeResponse.SubscriptionId); ContextResponses allEntities = client.GetAllEntitiesAsync().Result; foreach (var entity in allEntities.Responses) { Debug.WriteLine(entity.ContextElement.Id); } ContextResponse car1 = client.GetEntityAsync("Car1").Result; Debug.WriteLine(car1.ContextElement.Id); ContextTypesResponse types = client.GetTypesAsync().Result; foreach (var type in types.Types) { Debug.WriteLine(type.Name); } ContextAttributesResponse attributes = client.GetAttributesForTypeAsync("User").Result; foreach (var attribute in attributes.attributes) { Debug.WriteLine(attribute.Name); } ContextUnsubscribeResponse unsubscribe = client.UnsubscribeAsync(subscriptionResponse.SubscribeResponse.SubscriptionId).Result; Debug.WriteLine(unsubscribe.SubscriptionId); }
public void GetBodyAsStringGeneratesCorrectPolicy(bool inline, bool preserveContent, string expected) { var policy = ContextResponse.GetBodyAsString(inline, preserveContent); policy.Should().Be(expected); }
public void GetStatusReasonGeneratesCorrectPolicy(bool inline, string expected) { var policy = ContextResponse.GetStatusReason(inline); policy.Should().Be(expected); }
public void GetBodyAsJObjectGeneratesCorrectPolicy(bool inline, string expected) { var policy = ContextResponse.GetBodyAsJObject(inline); policy.Should().Be(expected); }