public static XDocument GetNowEnergy(EnergyPeriods periodToRequest) { XDocument energyPeriodRequest = GetEntirePowerInfo(); XElement periodRequestElement = null; switch (periodToRequest) { case EnergyPeriods.Day: periodRequestElement = new XElement("Device.System.Power.NowEnergy.Day"); break; case EnergyPeriods.Week: periodRequestElement = new XElement("Device.System.Power.NowEnergy.Week"); break; case EnergyPeriods.Month: periodRequestElement = new XElement("Device.System.Power.NowEnergy.Month"); break; default: throw new Exception(string.Format(@"Not supported parameter value: ""{0}"" for SmartPlugMessages.GetNowEnergy(EnergyPeriods periodToRequest)", periodToRequest.ToString())); } energyPeriodRequest.Descendants("NOW_POWER").First().Add(periodRequestElement); return(energyPeriodRequest); }
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"))); }
public static XDocument GetNowEnergy(EnergyPeriods periodToRequest) { XDocument energyPeriodRequest = GetEntirePowerInfo(); XElement periodRequestElement = null; switch (periodToRequest) { case EnergyPeriods.Day: periodRequestElement = new XElement("Device.System.Power.NowEnergy.Day"); break; case EnergyPeriods.Week: periodRequestElement = new XElement("Device.System.Power.NowEnergy.Week"); break; case EnergyPeriods.Month: periodRequestElement = new XElement("Device.System.Power.NowEnergy.Month"); break; default: throw new Exception(string.Format(@"Not supported parameter value: ""{0}"" for SmartPlugMessages.GetNowEnergy(EnergyPeriods periodToRequest)", periodToRequest.ToString())); } energyPeriodRequest.Descendants("NOW_POWER").First().Add(periodRequestElement); return energyPeriodRequest; }
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")); }