/// <summary>
        ///  See https://github.com/alexa/alexa-smarthome/blob/master/sample_messages/StateReport/StateReport.json
        /// </summary>
        /// <param name="requestDirective"></param>
        /// <returns></returns>
        private async Task <StateReportResponse> BuildDeviceStateReport(Directive requestDirective)
        {
            string token = requestDirective.Endpoint.Scope.Token;

            if (string.IsNullOrWhiteSpace(token))
            {
                throw new ArgumentException("Missing token");
            }

            var reponse = new StateReportResponse
            {
                Context = new Context
                {
                    Properties = new List <Property>(),
                },
                Event = ConstructReponseEvent(requestDirective, "StateReport"),
            };

            // Always add endpoint health...
            reponse.Context.Properties.Add(new ValueValueProperty
            {
                Namespace = "Alexa.EndpointHealth",
                Name      = "connectivity",
                Value     = new ValuePropertyValue {
                    Value = "ON"
                },
                TimeOfSample = DateTime.UtcNow,
                UncertaintyInMilliseconds = 600,
            });

            var deviceAndPort = new DeviceAndPort(requestDirective.Endpoint.EndpointId);
            var device        = await _devicesClient.GetDeviceAsync(token, deviceAndPort.Id);

            if (device == null)
            {
                return(reponse);
            }

            foreach (var supportedInterface in SupportedInterfaces)
            {
                if (device.Tags.Contains(supportedInterface))
                {
                    // This will itterate through the appropriate controllers
                    // and get them to create the required properties for the interface
                    // they support.
                    List <Property> properties = await CreateProperties(supportedInterface, token, device, deviceAndPort.Port);

                    reponse.Context.Properties.AddRange(properties);
                }
            }

            return(reponse);
        }
Exemple #2
0
        public async Task OnGetAsync(string deviceId)
        {
            var device = await _devicesClient.GetDeviceAsync(deviceId);

            Device = device is null ? new OwDeviceDetailsModel() : ToDetailsModel(device);
        }
Exemple #3
0
 protected Task <DeviceDto> GetDevice(string token, DeviceAndPort deviceAndPort)
 {
     return(_devicesClient.GetDeviceAsync(token, deviceAndPort.Id));
 }