Пример #1
0
        /// <summary>
        /// Gets the device by topic.
        /// </summary>
        /// <param name="topic">The topic.</param>
        /// <returns></returns>
        internal static MqttIcueDevice GetDeviceByTopic(string topic)
        {
            MqttIcueDevice device = GetDeviceByStateTopic(topic);

            if (device != null)
            {
                return(device);
            }
            return(GetDeviceBySetTopic(topic));
        }
Пример #2
0
        /// <summary>
        /// Adds the icue device. Sets the topics and create instances of MqttIcueDevice
        /// </summary>
        /// <param name="icueDevice">The icue device.</param>
        /// <returns>the newly created instance of MqttIcueDevice</returns>
        internal static MqttIcueDevice AddIcueDevice(Device icueDevice, int suffixNumber)
        {
            if (icueDevice == null)
            {
                return(null);
            }
            string entityId = icueDevice.CorsairDevice.Model.Replace(" ", "_").Replace(":", "_");

            if (suffixNumber > 0)
            {
                entityId += "_" + suffixNumber;
            }
            string         stateTopic     = String.Format("homeassistant/light/icue2mtt/{0}/state", entityId);
            string         commandTopic   = String.Format("homeassistant/light/icue2mtt/{0}/set", entityId);
            string         discoveryTopic = String.Format("homeassistant/light/icue2mtt/{0}/config", entityId);
            MqttIcueDevice mqttIcueDevice = new MqttIcueDevice(icueDevice, stateTopic, commandTopic, discoveryTopic, suffixNumber);

            if (stateTopicDeviceMap.ContainsKey(stateTopic))
            {
                for (int i = 0; i < devices.Count; i++)
                {
                    if (devices[i].IcueDevice.CorsairDevice.Model.Equals(mqttIcueDevice.IcueDevice.CorsairDevice.Model) && suffixNumber == devices[i].SuffixNumber)
                    {
                        devices[i]     = mqttIcueDevice;
                        icueDevices[i] = icueDevice;
                        break;
                    }
                }
                setTopicDeviceMap[commandTopic] = mqttIcueDevice;
                stateTopicDeviceMap[stateTopic] = mqttIcueDevice;
            }
            else
            {
                devices.Add(mqttIcueDevice);
                icueDevices.Add(icueDevice);
                setTopicDeviceMap.Add(commandTopic, mqttIcueDevice);
                stateTopicDeviceMap.Add(stateTopic, mqttIcueDevice);
            }
            return(mqttIcueDevice);
        }