public static Switch ToConfig(this clsButton button) { Switch ret = new Switch(); ret.name = Global.mqtt_discovery_name_prefix + button.Name; ret.state_topic = button.ToTopic(Topic.state); ret.command_topic = button.ToTopic(Topic.command); return(ret); }
private async Task PublishButtonState(clsButton button) { // Simulate a momentary press await PublishAsync(button.ToTopic(Topic.state), "ON"); await Task.Delay(1000); await PublishAsync(button.ToTopic(Topic.state), "OFF"); }
public static Switch ToConfig(this clsButton button) { Switch ret = new Switch(); ret.unique_id = $"{Global.mqtt_prefix}button{button.Number.ToString()}"; ret.name = Global.mqtt_discovery_name_prefix + button.Name; ret.state_topic = button.ToTopic(Topic.state); ret.command_topic = button.ToTopic(Topic.command); return(ret); }
private void PublishButtons() { log.Debug("Publishing {type}", "buttons"); for (ushort i = 1; i <= OmniLink.Controller.Buttons.Count; i++) { clsButton button = OmniLink.Controller.Buttons[i]; if (button.DefaultProperties == true) { PublishAsync(button.ToTopic(Topic.name), null); PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i}/config", null); continue; } // Buttons are off unless momentarily pressed PublishAsync(button.ToTopic(Topic.state), "OFF"); PublishAsync(button.ToTopic(Topic.name), button.Name); PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i}/config", JsonConvert.SerializeObject(button.ToConfig())); } }
private void PublishButtons() { log.Debug("Publishing buttons"); for (ushort i = 1; i < OmniLink.Controller.Buttons.Count; i++) { clsButton button = OmniLink.Controller.Buttons[i]; if (button.DefaultProperties == true) { MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i.ToString()}/config", null, MqttQualityOfServiceLevel.AtMostOnce, true); continue; } // Buttons are always off MqttClient.PublishAsync(button.ToTopic(Topic.state), "OFF", MqttQualityOfServiceLevel.AtMostOnce, true); MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i.ToString()}/config", JsonConvert.SerializeObject(button.ToConfig()), MqttQualityOfServiceLevel.AtMostOnce, true); } }