// Delete is the Configuration Topic with no Payload static void SendComponentDelete(Configuration.Mqtt mqttconfig) { mqttClient = new MqttClient(mqttconfig.broker); mqttClient.MqttMsgPublished += MqttClient_MqttMsgPublished; mqttClient.Connect(mqttconfig.clientid, mqttconfig.username, mqttconfig.password); Hass.Component.Sensor computersensor = new Hass.Component.Sensor(configuration.hass.uniqueid_base_prefix, "hardware_memory"); var config = computersensor.GetComponentConfiguration(); PrintConfig(config); mqttClient.Publish(config.Topic, Encoding.ASCII.GetBytes(""), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false); }
static void SendTestMessage(Configuration.Mqtt mqttconfig) { mqttClient = new MqttClient(mqttconfig.broker); Sensor.Computer computer = new Sensor.Computer(); Hass.Component.Sensor computersensor = new Hass.Component.Sensor(configuration.hass.uniqueid_base_prefix, "hardware_memory"); computersensor.SetState(computer.GetMemoryUsage()); string topic = computersensor.StateTopic; string payload = computersensor.Payload; Console.WriteLine(topic); Console.WriteLine(payload); mqttClient.MqttMsgPublished += MqttClient_MqttMsgPublished; mqttClient.Connect(mqttconfig.clientid, mqttconfig.username, mqttconfig.password); mqttClient.Publish(topic, Encoding.ASCII.GetBytes(payload), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false); }