예제 #1
0
        public void Update(ThermostatDevice device, FanDuration fduration, bool init = false)
        {
            if (false == init)
            {
                device.Duplicate(Reference);
            }

            Duration     = fduration;
            RollDuration = fduration;

            name                    = Reference.name;
            where_name              = Reference.where_name;
            is_online               = Reference.is_online;
            temperature_scale       = Reference.temperature_scale;
            ambient_temperature     = ("C" == temperature_scale) ? Reference.ambient_temperature_c : Reference.ambient_temperature_f;
            hvac_mode               = Reference.hvac_mode;
            target_temperature      = ("C" == temperature_scale) ? Reference.target_temperature_c : Reference.target_temperature_f;
            target_temperature_high = ("C" == temperature_scale) ? Reference.target_temperature_high_c : Reference.target_temperature_high_f;
            target_temperature_low  = ("C" == temperature_scale) ? Reference.target_temperature_low_c : Reference.target_temperature_low_f;
            has_fan                 = Reference.has_fan;
            fan_timer_active        = Reference.fan_timer_active;
            fan_timer_duration      = Reference.fan_timer_duration;
            is_locked               = Reference.is_locked;
            locked_temp_min         = ("C" == temperature_scale) ? Reference.locked_temp_min_c : Reference.locked_temp_min_f;
            locked_temp_max         = ("C" == temperature_scale) ? Reference.locked_temp_max_c : Reference.locked_temp_max_f;
            set_temperature_min     = 0;
            set_temperature_max     = 0;
            TickSpacing             = 0;
            Tick                    = 1; //("C" == temperature_scale) ? 1 : 2;
            FanRun                  = Reference.fan_timer_active == true;
            FanStop                 = Reference.fan_timer_active == false;

            Changed = false;
            Changed = true;
        }
예제 #2
0
        static bool InitDevice()
        {
            Task <bool> t = Task.Run(async() => await ThermostatAPI.GetDevices());

            t.Wait();

            if (t.Result)
            {
                int count = DeviceList.Count;
                if (0 == count)
                {
                    foreach (ThermostatDevice d in ThermostatAPI.ThermostatDevices)
                    {
                        FanDuration nfd = DurationList.Where(L => L.Duration == d.fan_timer_duration.ToString()).SingleOrDefault();

                        Thermostat nts = new Thermostat(d);
                        nts.Duration     = nfd;
                        nts.RollDuration = nfd;

                        nts.Tick = 1; //("C" == nts.temperature_scale) ? 1 : 2;

                        nts.FanRun  = nts.fan_timer_active == true;
                        nts.FanStop = nts.fan_timer_active == false;

                        DeviceList.Add(nts);
                    }
                }
                else
                {
                    if (ThermostatAPI.ThermostatDevices.Count < count)
                    {
                        DeviceList.Clear();
                    }

                    foreach (ThermostatDevice d in ThermostatAPI.ThermostatDevices)
                    {
                        FanDuration nfd = DurationList.Where(L => L.Duration == d.fan_timer_duration.ToString()).SingleOrDefault();

                        Thermostat tm = DeviceList.Where(T => T.device_id == d.device_id).SingleOrDefault();
                        if (null == tm || string.IsNullOrEmpty(tm.device_id))
                        {
                            Thermostat nts = new Thermostat(d);
                            nts.Duration     = nfd;
                            nts.RollDuration = nfd;

                            nts.Tick = 1; //("C" == nts.temperature_scale) ? 1 : 2;

                            nts.FanRun  = nts.fan_timer_active == true;
                            nts.FanStop = nts.fan_timer_active == false;

                            DeviceList.Add(nts);
                            continue;
                        }

                        if (null != tm || false == string.IsNullOrEmpty(tm.device_id))
                        {
                            tm.Update(d, nfd);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }