/// <summary>
        /// Handles a <see cref="Models.Request.SyncIntent"/>.
        /// </summary>
        /// <param name="intent">Intent to process.</param>
        /// <returns>A <see cref="Models.Response.SyncResponsePayload"/>.</returns>
        private Models.Response.SyncResponsePayload HandleSyncIntent(Models.Request.SyncIntent intent)
        {
            _log.LogInformation("Received SYNC intent");

            var syncResponsePayload = new Models.Response.SyncResponsePayload
            {
                AgentUserId = _config.GetValue <string>("googleHomeGraph:agentUserId"),
                Devices     = _deviceConfiguration.Values.Select(x => new Models.Response.Device
                {
                    Id              = x.Id,
                    Type            = x.Type,
                    RoomHint        = x.RoomHint,
                    WillReportState = x.WillReportState,
                    Traits          = x.Traits.Select(trait => trait.Trait).ToList(),
                    Attributes      = x.Traits
                                      .Where(trait => trait.Attributes != null)
                                      .SelectMany(trait => trait.Attributes)
                                      .ToDictionary(kv => kv.Key, kv => kv.Value),
                    Name       = x.Name,
                    DeviceInfo = x.DeviceInfo,
                    CustomData = x.CustomData
                }).ToList()
            };

            return(syncResponsePayload);
        }
Beispiel #2
0
        /// <summary>
        /// Handles a <see cref="Models.Request.SyncIntent"/>.
        /// </summary>
        /// <param name="intent">Intent to process.</param>
        /// <returns>A <see cref="Models.Response.SyncResponsePayload"/>.</returns>
        public Models.Response.SyncResponsePayload Handle(Models.Request.SyncIntent intent)
        {
            _log.LogInformation("Received SYNC intent");

            // Convert to an event to publish
            var commandEvent = new SyncIntentReceivedEvent {
                Time = DateTimeOffset.Now
            };

            _messageHub.Publish(commandEvent);

            var syncResponsePayload = new Models.Response.SyncResponsePayload
            {
                AgentUserId = _config.GetValue <string>("googleHomeGraph:agentUserId"),
                Devices     = _deviceRepository.GetAll()
                              .Where(device => !device.Disabled)
                              .Select(x => new Models.Response.Device
                {
                    Id              = x.Id,
                    Type            = x.Type,
                    RoomHint        = x.RoomHint,
                    WillReportState = x.WillReportState,
                    Traits          = x.Traits.Select(trait => trait.Trait).ToList(),
                    Attributes      = x.Traits
                                      .Where(trait => trait.Attributes != null)
                                      .SelectMany(trait => trait.Attributes)
                                      .ToDictionary(kv => kv.Key, kv => kv.Value),
                    Name       = x.Name,
                    DeviceInfo = x.DeviceInfo,
                    CustomData = x.CustomData
                }).ToList()
            };

            return(syncResponsePayload);
        }