/// <summary> /// Add Tinamous devices tagged with "Alexa.SmartDevice" /// </summary> /// <param name="request"></param> /// <param name="response"></param> /// <returns></returns> private async Task AddDeviceEndpoints(SmartHomeRequest request, DiscoverResponse response) { // Get a list of devices filtered by the Alexa.SmartDevice Tag from Tinamous. List <DeviceDto> devices = await _devicesClient.GetDevicesAsync(request.Directive.Payload.Scope.Token); LambdaLogger.Log("Found " + devices.Count + " devices from Tinamous."); // Add each of the devices as an endpoint. foreach (DeviceDto device in devices) { LambdaLogger.Log("Adding device " + device.DisplayName); if (!device.Connected) { LambdaLogger.Log("*** Device is not connected but adding it anyway: " + device.DisplayName); } if (!device.IsReporting) { LambdaLogger.Log("*** Device is not reporting but adding it anyway: " + device.DisplayName); } // Add the base device, regardless of if it's a 2 port, 4 port or whatever outlet device. // Allows SmartHome basics such as get temperature, and turn on/off to apply to all ports. response.Event.Payload.Endpoints.Add(CreateDeviceEndpoint(device)); // If the device is tagged as a multiport device (i.e. multiple outlets) // Try and also add each of the outlets as a device, giving it a name based // on a state tag set in the devices details. if (device.Tags.Contains("MultiPort")) { LambdaLogger.Log("Adding Multi-Port Device as multiple-devices for " + device.DisplayName); response.Event.Payload.Endpoints.AddRange(CreateMultiDeviceEndpoint(device)); } } LambdaLogger.Log("Found " + response.Event.Payload.Endpoints.Count + " devices."); }
public async Task OnGetAsync() { var devices = await _devicesClient.GetDevicesAsync(); Devices = devices is null?Array.Empty <OwDeviceIndexModel>() : ToIndexModel(devices); }