private void ProcessGetSpaceModeRequest(CustomRequest alexaRequest, CustomResponse response) { string toMatch = alexaRequest.payload.space.name; if (string.IsNullOrEmpty(toMatch) == false) { toMatch = toMatch.Trim(); var returnClause = new[] { "Name", "DisplayName", "Description", "CurrentScene", "Occupancy", "LastOccupied", "OccupancyCount", "OID", "OPATH", "OTYPENAME", "Type" }; dynamic whereClause = new ExpandoObject(); whereClause.TypeOf = PremiseServer.AlexaLocationClassPath; var sysRooms = PremiseServer.HomeObject.Select(returnClause, whereClause).GetAwaiter().GetResult(); foreach (var room in sysRooms) { string room_name = room.Name; string room_description = room.DisplayName; if ((!string.IsNullOrEmpty(room_description)) && (room_description.IndexOf("(Occupied)") != -1)) { room_description = room_description.Replace("(Occupied)", "").Trim(); } if ((room_name.Trim().ToLower() == toMatch) || (room_description.Trim().ToLower() == toMatch)) { InformLastContact("Get Space Status (success): " + toMatch).GetAwaiter().GetResult(); IPremiseObject this_room = PremiseServer.RootObject.GetObject(room.OID.ToString("B")).GetAwaiter().GetResult(); var devices = this_room.GetChildren().GetAwaiter().GetResult(); var count = 0; var onCount = 0; Temperature temperature = null; foreach (var device in devices) { if (device.IsOfType("{3470B9B5-E685-4EB2-ABC0-2F4CCD7F686A}").GetAwaiter().GetResult()) { count++; if (device.IsOfType("{65C7B5C2-153D-4711-BAD7-D334FDB12338}").GetAwaiter().GetResult()) { temperature = new Temperature(device.GetValue <double>("Temperature").GetAwaiter().GetResult()); } else if (device.IsOfType("{0B1DA7E1-1731-49AC-9814-47470E78EFAB}").GetAwaiter().GetResult()) { onCount += device.GetValue <bool>("PowerState").GetAwaiter().GetResult() ? 1 : 0; } } } // TODO: Aggregated properties //ICollection<IPremiseObject> i = this_room.GetAggregatedProperties().GetAwaiter().GetResult(); //response.payload.applianceRoomStatus.lastOccupied = room.lastOccupied.ToString(); response.payload.applianceRoomStatus = new RoomStatus { friendlyName = toMatch, occupied = room.Occupancy, occupancyCount = room.OccupancyCount, currentScene = room.CurrentScene, deviceCount = count.ToString() }; if (temperature != null) { response.payload.applianceRoomStatus.currentTemperature = double.Parse(string.Format("{0:N2}", temperature.Fahrenheit)).ToString(); } response.payload.applianceRoomStatus.lightsOnCount = onCount.ToString(); return; } } } if (string.IsNullOrEmpty(toMatch)) { InformLastContact("Get Space Status (space name missing in request)").GetAwaiter().GetResult(); } else { InformLastContact("Get Space Status (no such room): " + alexaRequest.payload.space.name.ToLower()).GetAwaiter().GetResult(); } response.header.@namespace = Faults.QueryNamespace; response.header.name = Faults.NoSuchTargetError; response.payload.exception = new ExceptionResponsePayload(); }