Exemple #1
0
        /// <summary>
        /// Gets the internal ID for devices or channels by given HomeMatic device or channel address
        /// </summary>
        /// <param name="address">HomeMatic device or channel address</param>
        /// <returns>Internal ID (iseId); if it is -1 we wasn't able to find a matching device or channel</returns>
        private int GetInternalIdByAddress(string address)
        {
            int result = -1;

            try
            {
                bool searchChannels = address.Contains(":");

                HMDevice        device  = null;
                HMDeviceChannel channel = null;

                device = devices.First(d => address.StartsWith(d.Address));

                if (searchChannels && device != null)
                {
                    channel = device.Channels.First(c => c.Address == address);
                }

                if (device != null && !String.IsNullOrEmpty(device.Address))
                {
                    result = device.InternalId;

                    if (channel != null && !String.IsNullOrEmpty(channel.Address))
                    {
                        result = channel.InternalId;
                    }
                }
            }
            catch (Exception)
            {
                // Seems that we have a problem finding this id in internal data so we let it go and pass a minus-one to indicate our disability
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Gets the device channel by given HomeMatic channel address
        /// </summary>
        /// <param name="address">HomeMatic channel address (ends with channel number separated by ':')</param>
        /// <returns>Channel</returns>
        public HMDeviceChannel GetChannelByAddress(string address)
        {
            try
            {
                if (address.Contains(":"))
                {
                    HMDevice device = GetDeviceByAddress(address);
                    if (device != null && device.Channels.Count > 0)
                    {
                        return(device.Channels.First(c => c.Address == address));
                    }
                }

                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets all devices including their channels but without any data point or state data
        /// </summary>
        /// <returns>List containing devices with channels</returns>
        private List <HMDevice> GetDevices()
        {
            List <HMDevice> result = new List <HMDevice>();

            // requesting devices list from HomeMatic XmlApi
            XmlDocument xmlDevices = GetApiData(xmlApiMethodDevice);

            // iterating devices
            foreach (XmlElement devElement in xmlDevices.DocumentElement.ChildNodes)
            {
                HMDevice device = new HMDevice()
                {
                    Name       = devElement.GetAttribute("name"),
                    Address    = devElement.GetAttribute("address"),
                    InternalId = int.Parse(devElement.GetAttribute("ise_id")),
                    DeviceType = devElement.GetAttribute("device_type")
                };

                // iterating channels
                foreach (XmlElement chanElement in devElement.ChildNodes)
                {
                    HMDeviceChannel channel = new HMDeviceChannel()
                    {
                        Name       = chanElement.GetAttribute("name"),
                        Address    = chanElement.GetAttribute("address"),
                        InternalId = int.Parse(chanElement.GetAttribute("ise_id")),
                    };

                    device.AddChannel(channel);
                }

                result.Add(device);
            }

            return(result);
        }