예제 #1
0
        private async Task UpdateFanByRoomAsync(string roomId, string fanId, bool isIncreased, CancellationToken cancellationToken = default)
        {
            var roomStatusData = await _smartThingsClient.GetCapabilityStatusAsync(roomId,
                                                                                   "main",
                                                                                   "switch",
                                                                                   cancellationToken);

            if (roomStatusData["switch"]["value"].GetString() == "on")
            {
                await UpdateFanSpeedAsync(fanId, isIncreased, cancellationToken);
            }
        }
예제 #2
0
        private async Task ProcessEventAsync(IEnumerable <HueEventData> events, CancellationToken cancellationToken = default)
        {
            var buttonEvent = events.SingleOrDefault(s => s.Id == DeviceConstants.buttonId);

            if (buttonEvent is not null)
            {
                switch (buttonEvent.Button.LastEvent)
                {
                case "short_release":
                    await SwitchComputerHaloAsync(cancellationToken);

                    break;

                case "long_release":

                    var stateResult = await _smartThingsClient.GetCapabilityStatusAsync(DeviceConstants.pcSwapId, "main", "switch", cancellationToken);

                    string state    = stateResult["switch"]["value"].GetString();
                    string newState = state == "on" ? "off" : "on";

                    await _smartThingsClient.ExecuteDeviceAsync(DeviceConstants.pcSwapId, new Models.SmartThings.DeviceExecuteModel
                    {
                        Component  = "main",
                        Capability = "switch",
                        Command    = newState
                    }, cancellationToken);

                    break;
                }
            }
        }