Contrequarte.SmartPlug.Core.SmartPlug.SetScheduleForWeekDay C# (CSharp) Method

SetScheduleForWeekDay() public method

public SetScheduleForWeekDay ( DayOfWeek dayOfWeek, IEnumerable entriesToSchedule ) : void
dayOfWeek DayOfWeek
entriesToSchedule IEnumerable
return void
        public void SetScheduleForWeekDay(DayOfWeek dayOfWeek, IEnumerable<ScheduledEntry> entriesToSchedule)
        {
            XDocument xmlSetScheduleMessage = SmartPlugMessages.SetScheduleForDayOfWeek(dayOfWeek);

            XElement scheduleNode = xmlSetScheduleMessage.Descendants("SCHEDULE").First();
            foreach (XElement xElement in scheduleNode.Elements())
            {
                if(xElement.Name.ToString().Contains("Device.System.Power.Schedule."))
                {
                    if(xElement.Name.ToString().Contains(".List"))
                    {
                        xElement.Value = PreparePowerScheduleList(entriesToSchedule);
                    }
                    else
                    {
                       xElement.Value =  PreparePowerSchedule(entriesToSchedule);
                    }
                }
            }

            XDocument xmlResponse = SendMessage(xmlSetScheduleMessage);
        }

Usage Example

Exemplo n.º 1
0
        static void PlugPlayDemo(SmartPlug smartPlug )
        {
            // initializing adapter
            //SmartPlug smartPlug = new SmartPlug(new IPAddress(new byte[] {a, b, c, d}), "lala", "9999"); //Please use your IP, UserName, PassWord...       

            //displaying current state on the 
            System.Console.WriteLine(string.Format("Current state of the smartplug is: {0}. Hit Enter key to continue!", smartPlug.Status.ToString()));
            System.Console.ReadLine();
            if (smartPlug.Status == SmartPlugState.Off)
            {
                smartPlug.Status = SmartPlugState.On;
            }
            else
            {
                smartPlug.Status = SmartPlugState.Off;
            }
            System.Console.WriteLine(string.Format("Now the state of the smartplug is: {0}. Hit Enter key to continue!", smartPlug.Status.ToString()));
            System.Console.ReadLine();

            //smartPlug.GetEntireSchedule();

            System.Console.WriteLine("Old schedule for Monday:");
            ShowSchedule(DayOfWeek.Monday, smartPlug);
            System.Console.WriteLine("Hit Enter key to continue!");
            System.Console.ReadLine();

            List<ScheduledEntry> newSchedule = new List<ScheduledEntry>();
            newSchedule.Add(new ScheduledEntry(new TimePeriod(new PointInTime(2, 0), new PointInTime(3, 0)),true));
            newSchedule.Add(new ScheduledEntry(new TimePeriod(new PointInTime(12, 0), new PointInTime(14, 30)),true));
            newSchedule.Add(new ScheduledEntry(new TimePeriod(new PointInTime(17, 10), new PointInTime(17, 45)),false));
            newSchedule.Add(new ScheduledEntry(new TimePeriod(new PointInTime(20, 20), new PointInTime(23, 13)),true));

            smartPlug.SetScheduleForWeekDay(DayOfWeek.Monday, newSchedule);

            System.Console.WriteLine("New schedule for Monday:");
            ShowSchedule(DayOfWeek.Monday, smartPlug);
            System.Console.WriteLine("Hit Enter key to continue!");
            System.Console.ReadLine();

            decimal thisMonthPowerConsumption = smartPlug.GetCummulatedPowerConsumption(EnergyPeriods.Month);
            System.Console.WriteLine(string.Format("The power consumption during this month has been {0} [kWh]. Hit Enter key to continue!",thisMonthPowerConsumption));
            System.Console.ReadLine();

        }