protected override List <MqttMessage> PrepareDiscoveryMessages()
        {
            var result = new List <MqttMessage>();

            foreach (var attr in ATTRIBUTES)
            {
                var payload = PrepareConfigPayload();
                payload.Add("unique_id", SensorUniqueId(attr));
                payload.Add("state_topic", StateTopic(attr));

                if (attr == "cpu")
                {
                    // payload.Add("icon", "mdi:cpu");
                    payload.Add("name", $"{FriendlyName()} - CPU usage");
                    payload.Add("unit_of_measurement", "%");
                }
                else if (attr == "ram")
                {
                    payload.Add("icon", "mdi:memory");
                    payload.Add("name", $"{FriendlyName()} - Free RAM");
                    payload.Add("unit_of_measurement", "MB");
                }

                var sensorType = SensorType.Sensor;
                var mqttMsg    = new MqttConfigMessage(sensorType, $"{WorkerType}_{attr}", payload);
                result.Add(mqttMsg);
            }

            return(result);
        }
        protected override List <MqttMessage> PrepareDiscoveryMessages()
        {
            var result = new List <MqttMessage>();

            var payload = PrepareConfigPayload();

            payload.Add("unique_id", SensorUniqueId("live"));
            payload.Add("name", $"{FriendlyName()} - {WorkerFriendlyType} - live");
            payload.Add("topic", StateTopic("live"));

            // Another HomeAssistant weirdness - camera is documented to be able to receive "device" dictionary, but there is no code support, thus throwing errors.
            // Reported here: https://github.com/home-assistant/home-assistant/issues/26024
            payload.Remove("device");

            var mqttMsg = new MqttConfigMessage(SensorType.Camera, $"{WorkerType}_live", payload);

            result.Add(mqttMsg);

            return(result);
        }
Exemple #3
0
        protected override List <MqttMessage> PrepareDiscoveryMessages()
        {
            var result = new List <MqttMessage>();

            foreach (var drive in Drives)
            {
                var diskLetter = drive.Name.Replace(":\\", "").ToLower();
                foreach (var attr in ATTRIBUTES)
                {
                    var payload = PrepareConfigPayload();
                    payload.Add("unique_id", SensorUniqueId(diskLetter, attr));
                    payload.Add("state_topic", StateTopic(diskLetter, attr));

                    switch (attr)
                    {
                    case "free":
                        payload.Add("name", $"{FriendlyName()} - Disk {diskLetter.ToUpper()} - free");
                        payload.Add("unit_of_measurement", "GB");
                        break;

                    case "free_pct":
                        payload.Add("name", $"{FriendlyName()} - Disk {diskLetter.ToUpper()} - free pct");
                        payload.Add("unit_of_measurement", "%");
                        break;

                    case "total":
                        payload.Add("name", $"{FriendlyName()} - Disk {diskLetter.ToUpper()} - total");
                        payload.Add("unit_of_measurement", "GB");
                        break;
                    }

                    var sensorType = SensorType.Sensor;
                    var mqttMsg    = new MqttConfigMessage(sensorType, $"{WorkerType}_{diskLetter}_{attr}", payload);
                    result.Add(mqttMsg);
                }
            }

            return(result);
        }
        protected override List <MqttMessage> PrepareDiscoveryMessages()
        {
            var result = new List <MqttMessage>();

            foreach (var attr in ATTRIBUTES)
            {
                var payload = PrepareConfigPayload();
                payload.Add("unique_id", SensorUniqueId(attr));
                payload.Add("name", $"{FriendlyName()} - {WorkerFriendlyType} - {attr.ToUppercaseFirst()}");
                payload.Add("state_topic", StateTopic(attr));

                if (attr == "level")
                {
                    payload.Add("unit_of_measurement", "%");
                    payload.Add("icon", "mdi:volume-medium");
                }
                else if (attr == "level_01")
                {
                    // Used for Media Player - there is no option to pass volume_level in universal platform as a template.
                    payload["state_topic"] = StateTopic("level");
                    payload.Add("value_template", "{{ (value|float) / 100 }}");
                    payload.Add("unit_of_measurement", "%");
                    payload.Add("icon", "mdi:volume-medium");
                }
                else if (attr == "mute")
                {
                    payload.Add("command_topic", CommandTopic(attr));
                    payload.Add("icon", "mdi:volume-off");
                }

                var sensorType = attr == "mute" ? SensorType.Switch : SensorType.Sensor;
                var mqttMsg    = new MqttConfigMessage(sensorType, $"{WorkerType}_{attr}", payload);
                result.Add(mqttMsg);
            }

            return(result);
        }