Exemplo n.º 1
0
 public VirtualSensor(string name, int index, SensorType sensorType,
                      Hardware.Hardware hardware, ISettings settings) :
     base(name, index, false, sensorType, hardware, null, settings)
 {
     val = new ValueString(settings.GetValue(new Identifier(Identifier, "valuestring").ToString(), "0"), SharedData.AllSensors);
     SetSensorType(sensorType);
     skip = 0;
     int.TryParse(settings.GetValue(new Identifier(Identifier, "skip").ToString(), "0"), out skip);
     skipCount = skip;   // Force initial update
 }
Exemplo n.º 2
0
        public FanController(byte id, List <ISensor> sensors, PersistentSettings settings)
        {
            this.id       = id;
            this.sensors  = sensors;
            this.settings = settings;

            identifier = new Identifier("FanController", id + "");


            if (!settings.Contains(new Identifier(identifier, "name").ToString()))
            {
                // Create new instsance
                Name  = "FanController " + id;
                value = new ValueString("", sensors);

                // Select the first IControl available
                foreach (ISensor s in sensors)
                {
                    if (s.Control == null)
                    {
                        continue;
                    }
                    else
                    {
                        Controlled = s.Control;
                        break;
                    }
                }
                sourceSensor = sensors[0];
            }
            else
            {
                // Load instance
                name  = settings.GetValue(new Identifier(identifier, "name").ToString(), "FanController " + id);
                value = new ValueString(settings.GetValue(new Identifier(identifier, "valueString").ToString(), "0"), sensors);

                string c = settings.GetValue(new Identifier(identifier, "controlled").ToString(), null);
                foreach (ISensor s in sensors)
                {
                    if (s.Control == null)
                    {
                        continue;
                    }
                    if (s.Control.Identifier.ToString() == c)
                    {
                        controlled = s.Control;
                        break;
                    }
                }
            }

            if (controlled == null)
            {
                throw new Exception("No supported fan control found");
            }

            curve        = new FanControlCurve(new Identifier(identifier, "curve"), settings);
            enabled      = bool.Parse(settings.GetValue(new Identifier(identifier, "enabled").ToString(), "false"));
            hysteresis   = float.Parse(settings.GetValue(new Identifier(identifier, "hysteresis").ToString(), "1").Replace('.', ','));
            sourceSensor = SharedData.AllSensors.GetByIdentifier(settings.GetValue(new Identifier(identifier, "sourceSensor").ToString(), "0"));
            if (sourceSensor == null)
            {
                sourceSensor = sensors[0];
            }
            source     = (InputSource)int.Parse(settings.GetValue(new Identifier(identifier, "inputSource").ToString(), "0"));
            tryRestart = bool.Parse(settings.GetValue(new Identifier(identifier, "tryRestart").ToString(), "true"));
        }