コード例 #1
0
        public DialogHMData(HMBase hmElement)
        {
            HMElement = hmElement;
            InitializeComponent();

            try
            {
                Text += HMElement.GetType().Name;
                lblDataPointName.Text = hmElement.ToString();

                switch (Text)
                {
                case "HMDevice":
                    txtValue.ReadOnly = true;
                    txtValue.Text     = "A device can not be set directly; choose a channel or data point!";
                    break;

                case "HMDeviceChannel":
                    HMDeviceChannel chan = (HMDeviceChannel)HMElement;
                    txtValue.Text  = String.Concat(chan.PrimaryValue);
                    btnSet.Enabled = true;
                    break;

                case "HMDeviceDataPoint":
                    HMDeviceDataPoint dp = (HMDeviceDataPoint)HMElement;
                    txtValue.Text  = String.Concat(dp.ValueString);
                    btnSet.Enabled = true;
                    break;

                case "HMSystemMessage":
                    txtValue.ReadOnly = true;
                    txtValue.Text     = "A message can not be set directly; choose a channel or data point!";
                    break;

                case "HMSystemVariable":
                    HMSystemVariable svar = (HMSystemVariable)HMElement;
                    txtValue.Text  = String.Concat(svar.Value);
                    btnSet.Enabled = true;
                    break;

                default:
                    txtValue.ReadOnly = true;
                    txtValue.Text     = "Don't know what it is; choose a channel or data point!";
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Identifing Homematic element failed...\n" + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates the global list of system variables
        /// </summary>
        public void UpdateVariables()
        {
            // requesting system variables list from HomeMatic XmlApi
            XmlDocument xmlVariables = GetApiData(xmlApiMethodVariable);

            // clear current collection
            variables.Clear();

            // iterating variables
            foreach (XmlElement varElement in xmlVariables.DocumentElement.ChildNodes)
            {
                try
                {
                    HMSystemVariable variable = new HMSystemVariable()
                    {
                        InternalId          = int.Parse(varElement.GetAttribute("ise_id")),
                        Name                = varElement.GetAttribute("name"),
                        ValueType           = varElement.GetAttribute("type"),
                        ValueUnit           = varElement.GetAttribute("unit"),
                        ValueString         = varElement.GetAttribute("value"),
                        IsLogged            = bool.Parse(varElement.GetAttribute("logged")),
                        IsVisible           = bool.Parse(varElement.GetAttribute("visible")),
                        LastUpdateTimeStamp = long.Parse(varElement.GetAttribute("timestamp"))
                    };

                    if (variable != null && !String.IsNullOrEmpty(variable.ValueType))
                    {
                        if (int.Parse(variable.ValueType) == 16)
                        {
                            variable.SetValuesIndex(varElement.GetAttribute("value_list"));
                        }
                        else if (int.Parse(variable.ValueType) == 2)
                        {
                            variable.SetValuesIndex(varElement.GetAttribute("value_name_1"), varElement.GetAttribute("value_name_0"));
                        }
                    }

                    variables.Add(variable);
                }
                catch (Exception)
                {
                    // Ignore mismatched variable
                }
            }
        }