private async Task SpinFanAsync(string fanId, string monitorId, int targetTemp, CancellationToken cancellationToken = default) { var tempData = await _smartThingsClient.GetCapabilityStatusAsync(monitorId, "main", "temperatureMeasurement", cancellationToken); var fanData = await _smartThingsClient.GetCapabilityStatusAsync(fanId, "main", "fanSpeed", cancellationToken); float currentTemp = tempData["temperature"]["value"].GetSingle(); int fanSpeed = fanData["fanSpeed"]["value"].GetInt32(); if (currentTemp < targetTemp) { if (fanSpeed > 1) { --fanSpeed; await IncreaseFanAsync(); } else if (fanSpeed == 1) { await SwitchFanAsync("off"); } } else if (currentTemp > targetTemp + 1) { if (fanSpeed == 0) { await SwitchFanAsync("on"); } else if (fanSpeed < 3) { ++fanSpeed; await IncreaseFanAsync(); } } async Task IncreaseFanAsync() { await _smartThingsClient.ExecuteDeviceAsync(fanId, new Models.SmartThings.DeviceExecuteModel { Component = "main", Capability = "fanSpeed", Command = "setFanSpeed", Arguments = new object[] { fanSpeed } }, cancellationToken); } async Task SwitchFanAsync(string value) { await _smartThingsClient.ExecuteDeviceAsync(fanId, new Models.SmartThings.DeviceExecuteModel { Component = "main", Capability = "switch", Command = value, }, cancellationToken); } }