コード例 #1
0
        public static Switch ToConfigSwitch(this clsUnit unit)
        {
            Switch ret = new Switch();

            ret.name          = Global.mqtt_discovery_name_prefix + unit.Name;
            ret.state_topic   = unit.ToTopic(Topic.state);
            ret.command_topic = unit.ToTopic(Topic.command);
            return(ret);
        }
コード例 #2
0
        private void PublishUnitState(clsUnit unit)
        {
            MqttClient.PublishAsync(unit.ToTopic(Topic.state), unit.ToState(), MqttQualityOfServiceLevel.AtMostOnce, true);

            if (unit.Number < 385)
            {
                MqttClient.PublishAsync(unit.ToTopic(Topic.brightness_state), unit.ToBrightnessState().ToString(), MqttQualityOfServiceLevel.AtMostOnce, true);
            }
        }
コード例 #3
0
        private void PublishUnitState(clsUnit unit)
        {
            PublishAsync(unit.ToTopic(Topic.state), unit.ToState());

            if (unit.Number < 385)
            {
                PublishAsync(unit.ToTopic(Topic.brightness_state), unit.ToBrightnessState().ToString());
            }
        }
コード例 #4
0
        public static Switch ToConfigSwitch(this clsUnit unit)
        {
            Switch ret = new Switch();

            ret.unique_id     = $"{Global.mqtt_prefix}unit{unit.Number.ToString()}switch";
            ret.name          = Global.mqtt_discovery_name_prefix + unit.Name;
            ret.state_topic   = unit.ToTopic(Topic.state);
            ret.command_topic = unit.ToTopic(Topic.command);
            return(ret);
        }
コード例 #5
0
        public static Light ToConfig(this clsUnit unit)
        {
            Light ret = new Light();

            ret.name                     = Global.mqtt_discovery_name_prefix + unit.Name;
            ret.state_topic              = unit.ToTopic(Topic.state);
            ret.command_topic            = unit.ToTopic(Topic.command);
            ret.brightness_state_topic   = unit.ToTopic(Topic.brightness_state);
            ret.brightness_command_topic = unit.ToTopic(Topic.brightness_command);
            return(ret);
        }
コード例 #6
0
        public static Light ToConfig(this clsUnit unit)
        {
            Light ret = new Light();

            ret.unique_id                = $"{Global.mqtt_prefix}unit{unit.Number.ToString()}light";
            ret.name                     = Global.mqtt_discovery_name_prefix + unit.Name;
            ret.state_topic              = unit.ToTopic(Topic.state);
            ret.command_topic            = unit.ToTopic(Topic.command);
            ret.brightness_state_topic   = unit.ToTopic(Topic.brightness_state);
            ret.brightness_command_topic = unit.ToTopic(Topic.brightness_command);
            return(ret);
        }
コード例 #7
0
ファイル: MQTTModule.cs プロジェクト: rcjacoby/OmniLinkBridge
        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()));
                }
            }
        }