mirror of
https://github.com/excaliburpartners/OmniLinkBridge
synced 2025-05-07 01:13:12 +00:00
- Add prefix for MQTT discovery entity name
This commit is contained in:
parent
d65f920c7e
commit
fdaa26830e
|
@ -50,6 +50,7 @@ namespace OmniLinkBridge
|
|||
public static string mqtt_password;
|
||||
public static string mqtt_prefix;
|
||||
public static string mqtt_discovery_prefix;
|
||||
public static string mqtt_discovery_name_prefix;
|
||||
public static HashSet<int> mqtt_discovery_ignore_zones;
|
||||
public static HashSet<int> mqtt_discovery_ignore_units;
|
||||
public static ConcurrentDictionary<int, OverrideZone> mqtt_discovery_override_zone;
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Alarm ToConfig(this clsArea area)
|
||||
{
|
||||
Alarm ret = new Alarm();
|
||||
ret.name = area.Name;
|
||||
ret.name = Global.mqtt_discovery_name_prefix + area.Name;
|
||||
ret.state_topic = area.ToTopic(Topic.basic_state);
|
||||
ret.command_topic = area.ToTopic(Topic.command);
|
||||
return ret;
|
||||
|
@ -82,7 +82,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Sensor ToConfigTemp(this clsZone zone)
|
||||
{
|
||||
Sensor ret = new Sensor();
|
||||
ret.name = zone.Name;
|
||||
ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp";
|
||||
ret.device_class = Sensor.DeviceClass.temperature;
|
||||
ret.state_topic = zone.ToTopic(Topic.current_temperature);
|
||||
ret.unit_of_measurement = "°F";
|
||||
|
@ -92,7 +92,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Sensor ToConfigHumidity(this clsZone zone)
|
||||
{
|
||||
Sensor ret = new Sensor();
|
||||
ret.name = zone.Name;
|
||||
ret.name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Humidity";
|
||||
ret.device_class = Sensor.DeviceClass.humidity;
|
||||
ret.state_topic = zone.ToTopic(Topic.current_humidity);
|
||||
ret.unit_of_measurement = "%";
|
||||
|
@ -102,7 +102,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Sensor ToConfigSensor(this clsZone zone)
|
||||
{
|
||||
Sensor ret = new Sensor();
|
||||
ret.name = zone.Name;
|
||||
ret.name = Global.mqtt_discovery_name_prefix + zone.Name;
|
||||
|
||||
switch (zone.ZoneType)
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static BinarySensor ToConfig(this clsZone zone)
|
||||
{
|
||||
BinarySensor ret = new BinarySensor();
|
||||
ret.name = zone.Name;
|
||||
ret.name = Global.mqtt_discovery_name_prefix + zone.Name;
|
||||
|
||||
Global.mqtt_discovery_override_zone.TryGetValue(zone.Number, out OverrideZone override_zone);
|
||||
|
||||
|
@ -213,7 +213,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Light ToConfig(this clsUnit unit)
|
||||
{
|
||||
Light ret = new Light();
|
||||
ret.name = unit.Name;
|
||||
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);
|
||||
|
@ -224,7 +224,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Switch ToConfigSwitch(this clsUnit unit)
|
||||
{
|
||||
Switch ret = new Switch();
|
||||
ret.name = unit.Name;
|
||||
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;
|
||||
|
@ -253,7 +253,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Sensor ToConfigHumidity(this clsThermostat zone)
|
||||
{
|
||||
Sensor ret = new Sensor();
|
||||
ret.name = zone.Name;
|
||||
ret.name = Global.mqtt_discovery_name_prefix + zone.Name;
|
||||
ret.device_class = Sensor.DeviceClass.humidity;
|
||||
ret.state_topic = zone.ToTopic(Topic.current_humidity);
|
||||
ret.unit_of_measurement = "%";
|
||||
|
@ -263,7 +263,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Climate ToConfig(this clsThermostat thermostat)
|
||||
{
|
||||
Climate ret = new Climate();
|
||||
ret.name = thermostat.Name;
|
||||
ret.name = Global.mqtt_discovery_name_prefix + thermostat.Name;
|
||||
ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature);
|
||||
|
||||
ret.temperature_low_state_topic = thermostat.ToTopic(Topic.temperature_heat_state);
|
||||
|
@ -303,7 +303,7 @@ namespace OmniLinkBridge.MQTT
|
|||
public static Switch ToConfig(this clsButton button)
|
||||
{
|
||||
Switch ret = new Switch();
|
||||
ret.name = button.Name;
|
||||
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;
|
||||
|
|
|
@ -36,9 +36,15 @@ mqtt_server =
|
|||
mqtt_port = 1883
|
||||
mqtt_username =
|
||||
mqtt_password =
|
||||
# If you have multiple Omni Controllers you will want to change the
|
||||
# mqtt_prefix and mqtt_discovery_name_prefix to prevent collisions.
|
||||
# Prefix for MQTT state / command topics
|
||||
mqtt_prefix = omnilink
|
||||
# Prefix for Home Assistant discovery
|
||||
mqtt_discovery_prefix = homeassistant
|
||||
# specify a range of numbers like 1,2,3,5-10
|
||||
# Prefix for Home Assistant entity names
|
||||
mqtt_discovery_name_prefix =
|
||||
# Specify a range of numbers like 1,2,3,5-10
|
||||
mqtt_discovery_ignore_zones =
|
||||
mqtt_discovery_ignore_units =
|
||||
# device_class must be battery, door, garage_door, gas, moisture, motion, problem, smoke, or window
|
||||
|
|
|
@ -57,6 +57,11 @@ namespace OmniLinkBridge
|
|||
Global.mqtt_password = settings["mqtt_password"];
|
||||
Global.mqtt_prefix = settings["mqtt_prefix"] ?? "omnilink";
|
||||
Global.mqtt_discovery_prefix = settings["mqtt_discovery_prefix"] ?? "homeassistant";
|
||||
Global.mqtt_discovery_name_prefix = settings["mqtt_discovery_name_prefix"] ?? string.Empty;
|
||||
|
||||
if (!string.IsNullOrEmpty(Global.mqtt_discovery_name_prefix))
|
||||
Global.mqtt_discovery_name_prefix = Global.mqtt_discovery_name_prefix + " ";
|
||||
|
||||
Global.mqtt_discovery_ignore_zones = ValidateRange(settings, "mqtt_discovery_ignore_zones");
|
||||
Global.mqtt_discovery_ignore_units = ValidateRange(settings, "mqtt_discovery_ignore_units");
|
||||
Global.mqtt_discovery_override_zone = LoadOverrideZone(settings, "mqtt_discovery_override_zone");
|
||||
|
|
Loading…
Reference in a new issue