コード例 #1
0
ファイル: Security.cs プロジェクト: brianavid/Avid4G.Net
 public static void TurnZoneOff(
     string name)
 {
     foreach (Device d in Zones[name])
     {
         TP_Link.TurnOff(d.ipAddress, d.name, d.isSocket);
     }
     ZoneStates[name] = "off";
 }
コード例 #2
0
        // GET: Security/Off?id=NNN
        public ActionResult Off(
            string id,
            string socket = "no")
        {
            string ipAddr = "192.168.1." + id;

            TP_Link.TurnOff(ipAddr, ipAddr, socket != "no");
            return(Content("OK"));
        }
コード例 #3
0
ファイル: Security.cs プロジェクト: brianavid/Avid4G.Net
    /// <summary>
    /// Apply any initial on/off settings in the current schedule, recording the current state for each device
    /// </summary>
    static void InitSchedule()
    {
        if (CurrentProfileSchedules.radioSchedule != null)
        {
            if (CurrentProfileSchedules.radioSchedule.initiallyOn || CurrentProfileSchedules.radioSchedule.initiallyOff || CurrentProfileSchedules.radioSchedule.onPeriods.Any())
            {
                Running.ExitAllPrograms();
                DesktopClient.SendSpecialkey("ClearDesktop");
            }

            if (CurrentProfileSchedules.radioSchedule.initiallyOn)
            {
                Receiver.Security();
                RadioState = "on";
            }

            if (CurrentProfileSchedules.radioSchedule.initiallyOff)
            {
                RadioState = "off";
            }
        }

        foreach (var zoneKV in CurrentProfileSchedules.zoneSchedules)
        {
            if (zoneKV.Value.initiallyOn && Zones.ContainsKey(zoneKV.Key))
            {
                foreach (Device d in Zones[zoneKV.Key])
                {
                    TP_Link.TurnOn(d.ipAddress, d.name, d.isSocket);
                }
                ZoneStates[zoneKV.Key] = "on";
            }
            if (zoneKV.Value.initiallyOff && Zones.ContainsKey(zoneKV.Key))
            {
                foreach (Device d in Zones[zoneKV.Key])
                {
                    TP_Link.TurnOff(d.ipAddress, d.name, d.isSocket);
                }
                ZoneStates[zoneKV.Key] = "off";
            }
        }
    }
コード例 #4
0
ファイル: Security.cs プロジェクト: brianavid/Avid4G.Net
    /// <summary>
    /// Periodically (typically evey minute) check the current time against the schedule to determine if ant lights need switching
    /// </summary>
    /// <param name="when"></param>
    public static void Tick(DateTime when)
    {
        if (CurrentProfileSchedules != null)
        {
            //  If the date has changed, re-load the profile in order to get the new day's schedule
            if (when.Date != DateLoaded)
            {
                LoadProfile(CurrentSecurityProfileId, true);
            }

            if (CurrentProfileSchedules.radioSchedule.onPeriods.Count != 0)
            {
                try
                {
                    var radioOn = TestIfOn(when, CurrentProfileSchedules.radioSchedule.onPeriods);
                    if (radioOn && RadioState != "on")
                    {
                        Receiver.Security();
                        RadioState = "on";
                    }
                    else if (!radioOn && RadioState != "off")
                    {
                        Receiver.TurnOff();
                        RadioState = "off";
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Can't schedule Radio: {0}", ex.ToString());
                }
            }

            foreach (var zoneKV in CurrentProfileSchedules.zoneSchedules)
            {
                if (zoneKV.Value.onPeriods.Count != 0 && Zones.ContainsKey(zoneKV.Key))
                {
                    try
                    {
                        var zoneOn = TestIfOn(when, zoneKV.Value.onPeriods);
                        if (zoneOn && (!ZoneStates.ContainsKey(zoneKV.Key) || ZoneStates[zoneKV.Key] != "on"))
                        {
                            foreach (Device d in Zones[zoneKV.Key])
                            {
                                TP_Link.TurnOn(d.ipAddress, d.name, d.isSocket);
                            }
                            ZoneStates[zoneKV.Key] = "on";
                        }
                        if (!zoneOn && (!ZoneStates.ContainsKey(zoneKV.Key) || ZoneStates[zoneKV.Key] != "off"))
                        {
                            foreach (Device d in Zones[zoneKV.Key])
                            {
                                TP_Link.TurnOff(d.ipAddress, d.name, d.isSocket);
                            }
                            ZoneStates[zoneKV.Key] = "off";
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Can't schedule Zone {0}: {1}", zoneKV.Key, ex.ToString());
                    }
                }
            }
        }
    }