Ejemplo n.º 1
0
        /// <summary>
        /// Get the positions of all the switches.
        /// </summary>
        /// <returns>The switch position status.</returns>
        public async Task <IEnumerable <TOut> > List()
        {
            var switches = new List <TOut>();

            foreach (var bridge in clientManager.GetClientNames())
            {
                try
                {
                    var lightInfos = await clientManager.GetClient(bridge).GetSwitches();

                    var tasks = lightInfos.Select(async lightInfo =>
                    {
                        try
                        {
                            var light = await clientManager.GetClient(bridge).GetSwitch(lightInfo.Data.SwitchId.ToString());
                            return(new TOut()
                            {
                                Brightness = light.Data.Brightness,
                                Value = light.Data.Value,
                                HexColor = light.Data.HexColor,
                                Id = light.Data.SwitchId.ToString(),
                                Name = $"{bridge} - {light.Data.Name}",
                                Bridge = bridge,
                                Subsystem = SubsystemName
                            });
                        }
                        catch (Exception ex)
                        {
                            logger.LogError(ex, $"'{ex.GetType().FullName}' occured with the loading switches. The switch '{lightInfo.Data.Name}' id: '{lightInfo.Data.SwitchId}' was skipped.{Environment.NewLine}Full Exception:");

                            return(new TOut()
                            {
                                Brightness = lightInfo.Data.Brightness,
                                Value = lightInfo.Data.Value,
                                HexColor = lightInfo.Data.HexColor,
                                Id = lightInfo.Data.SwitchId.ToString(),
                                Name = $"{bridge} - {lightInfo.Data.Name}",
                                Bridge = bridge,
                                Subsystem = SubsystemName
                            });
                        }
                    });
                    foreach (var task in tasks)
                    {
                        switches.Add(await task);
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, $"'{ex.GetType().FullName}' occured with the loading switches. The bridge '{bridge}' was skipped.{Environment.NewLine}Full Exception:");
                }
            }

            return(switches.ToList());
        }
Ejemplo n.º 2
0
        public async Task <TOut> Get(string bridge, string id)
        {
            var thermostat = await clientManager.GetClient(bridge).GetThermostat(id);

            return(new TOut()
            {
                Id = thermostat.Data.ThermostatId.ToString(),
                Name = thermostat.Data.Name,
                Bridge = bridge,
                Subsystem = SubsystemName,
                HeatTemp = thermostat.Data.HeatTemp,
                CoolTemp = thermostat.Data.CoolTemp,
                Mode = (Core.Mode)thermostat.Data.Mode,
                Fan = (Core.FanSetting)thermostat.Data.Fan,
                State = (Core.State)thermostat.Data.State,
                FanState = (Core.FanState)thermostat.Data.FanState,
                SpaceTemp = thermostat.Data.SpaceTemp,
                Humidity = thermostat.Data.Humidity
            });
        }