public async Task <bool> Set(int id, string kind, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                value = kind;
                kind  = null;
            }

            _logger.LogInformation($"Set: {id}: {value}");

            var values = Regex.Split(value, "[^\\d]+");

            if (values.Length == 3)
            {
                var hsv = new HsvValue
                {
                    H = int.Parse(values[0]),
                    S = int.Parse(values[1]),
                    V = int.Parse(values[2])
                };
                return(await _session.SetDeviceValue(id, kind, hsv));
            }

            if (int.TryParse(value, out var intValue))
            {
                return(await _session.SetDeviceValue(id, kind, intValue));
            }
            if (bool.TryParse(value, out var boolValue))
            {
                return(await _session.SetDeviceValue(id, kind, boolValue));
            }
            return(await _session.SetDeviceValue(id, kind, value));
        }
Пример #2
0
        public async Task <bool> SetDeviceValue(int id, string kind, HsvValue value)
        {
            var device = GetDevice(id);

            var command = device?.GetHsvCommand(kind, value);

            if (command == null)
            {
                return(false);
            }

            if (!await _client.SendCommand(command))
            {
                return(false);
            }

            device.UpdateValue(kind, command.Value);

            return(true);
        }
 public SetDeviceHsvValue(int deviceId, HsvValue value) : base("setDeviceValue")
 {
     DeviceId = deviceId;
     Value    = value;
 }