예제 #1
0
        private void PublishUnits()
        {
            log.Debug("Publishing units");

            for (ushort i = 1; i < OmniLink.Controller.Units.Count; i++)
            {
                clsUnit unit = OmniLink.Controller.Units[i];

                if (unit.DefaultProperties == true || Global.mqtt_discovery_ignore_units.Contains(unit.Number))
                {
                    string type = i < 385 ? "light" : "switch";
                    MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/{type}/{Global.mqtt_prefix}/unit{i.ToString()}/config", null, MqttQualityOfServiceLevel.AtMostOnce, true);
                    continue;
                }

                PublishUnitState(unit);

                if (i < 385)
                {
                    MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/light/{Global.mqtt_prefix}/unit{i.ToString()}/config",
                                            JsonConvert.SerializeObject(unit.ToConfig()), MqttQualityOfServiceLevel.AtMostOnce, true);
                }
                else
                {
                    MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/unit{i.ToString()}/config",
                                            JsonConvert.SerializeObject(unit.ToConfigSwitch()), MqttQualityOfServiceLevel.AtMostOnce, true);
                }
            }
        }
예제 #2
0
        private void PublishUnits()
        {
            log.Debug("Publishing {type}", "units");

            for (ushort i = 1; i <= OmniLink.Controller.Units.Count; i++)
            {
                clsUnit unit = OmniLink.Controller.Units[i];

                if (unit.DefaultProperties == true)
                {
                    PublishAsync(unit.ToTopic(Topic.name), null);
                }
                else
                {
                    PublishUnitState(unit);
                    PublishAsync(unit.ToTopic(Topic.name), unit.Name);
                }

                if (unit.DefaultProperties == true || Global.mqtt_discovery_ignore_units.Contains(unit.Number))
                {
                    string type = i < 385 ? "light" : "switch";
                    PublishAsync($"{Global.mqtt_discovery_prefix}/{type}/{Global.mqtt_prefix}/unit{i}/config", null);
                    continue;
                }

                if (i < 385)
                {
                    PublishAsync($"{Global.mqtt_discovery_prefix}/light/{Global.mqtt_prefix}/unit{i}/config",
                                 JsonConvert.SerializeObject(unit.ToConfig()));
                }
                else
                {
                    PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/unit{i}/config",
                                 JsonConvert.SerializeObject(unit.ToConfigSwitch()));
                }
            }
        }