Exemple #1
0
        public IEnumerable <ScheduledEntry> GetScheduleForWeekDay(DayOfWeek dayOfWeek)
        {
            /* expected return looks like that:
             *<SMARTPLUG id="edimax">
             *   <CMD id="get">
             *      <SCHEDULE>
             *         <Device.System.Power.Schedule.0.List>00011-0c0m1-m0mu1-n0nP1</Device.System.Power.Schedule.0.List>
             *      </SCHEDULE>
             *   </CMD>
             *</SMARTPLUG>
             */

            XDocument plugRequest  = SmartPlugMessages.GetScheduledListForDayOfWeek(dayOfWeek);
            XDocument plugResponse = SendMessage(plugRequest);

            string scheduledList = plugResponse.Descendants("SCHEDULE").First().Elements().First().Value;

            return(TimePeriod.EdimaxScheduleList2ScheduledEntries(scheduledList));
        }
Exemple #2
0
        public decimal GetCummulatedPowerConsumption(EnergyPeriods energyPeriod)
        {
            // power metrics are available for model "SP2101W " model "SP1101W" doesen't support power metrics!
            if (this.smartPlugDetails.Model.ToUpper() != "SP2101W")
            {
                return(0);
            }

            /*
             * <Device.System.Power.NowEnergy.Month>0.107</Device.System.Power.NowEnergy.Month>
             */
            XDocument plugRequest  = SmartPlugMessages.GetNowEnergy(energyPeriod);
            XDocument plugResponse = SendMessage(plugRequest);

            string powerConsumption = plugResponse.Descendants("NOW_POWER").First().Elements().First().Value;

            if (string.IsNullOrEmpty(powerConsumption))
            {
                return(0);
            }

            return(Convert.ToDecimal(powerConsumption, new CultureInfo("en-US")));
        }
Exemple #3
0
        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);
        }