コード例 #1
0
        public IList<Thermostat> GetThermostatList()
        {
            List<Thermostat> thermostatList = new List<Thermostat>();

            XmlDocument document = GetXmlDocumentFromFhem("xmllist");
            XmlNodeList nodeList = document.SelectNodes("//FHT");

            foreach (XmlNode node in nodeList)
            {
                XmlNode nameNode = node.SelectSingleNode("./INT[@key='NAME']");
                XmlNode currentStateNode = node.SelectSingleNode("./STATE[@key='measured-temp']");
                XmlNode desiredStateNode = node.SelectSingleNode("./STATE[@key='desired-temp']");
                //XmlNode idNode = node.SelectSingleNode("./INT[@key='DEF']");

                Thermostat thermostat = new Thermostat()
                {
                    Name = nameNode.Attributes["value"].Value,
                    CurrentTemperature = currentStateNode == null
                        ? "Unavailable"
                        : currentStateNode.Attributes["value"].Value,
                    DesiredTemperature = desiredStateNode == null
                        ? "Unavailable"
                        : desiredStateNode.Attributes["value"].Value
                };

                thermostatList.Add(thermostat);
            }

            return thermostatList;
        }
コード例 #2
0
 public static ThermostatViewModel DomainToViewModel(Thermostat input)
 {
     return new ThermostatViewModel
     {
         Name = input.Name,
         Actuator = new MeasurementViewModel<string>(input.Actuator.Value, input.Actuator.Timestamp),
         CurrentTemp = new MeasurementViewModel<string>(input.CurrentTemp.Value.ToString(), input.CurrentTemp.Timestamp),
         DesiredTemp = new MeasurementViewModel<float>(input.DesiredTemp.Value ?? 5, input.DesiredTemp.Timestamp),
         Mode = new MeasurementViewModel<string>(input.Mode.Value == ThermostatMode.Auto ? "Auto" : "Manu", input.Mode.Timestamp),
         DaySchedules = GetDaySchedules(input)
     };
 }
コード例 #3
0
        private static DayScheduleViewModel[] GetDaySchedules(Thermostat input)
        {
            var result = new DayScheduleViewModel[7];
            for (int inputIndex = 0; inputIndex < input.Schedule.Length; inputIndex++)
            {
                var daySchedule = input.Schedule[inputIndex];

                var outputIndex = (inputIndex == 0 ? 6 : inputIndex - 1);
                result[outputIndex] = GetDayScheduleViewModel(inputIndex, daySchedule.Periods.ToList());
            }

            return result;
        }