- Add MQTT unit scene, update packages, and fix compiler warnings

This commit is contained in:
Ryan Wagoner 2020-11-02 21:14:01 -05:00
parent 084fb9a473
commit 85c549d5dd
8 changed files with 226 additions and 156 deletions

View file

@ -7,16 +7,18 @@ namespace OmniLinkBridge.MQTT
{
public static string ToTopic(this clsArea area, Topic topic)
{
return $"{Global.mqtt_prefix}/area{area.Number.ToString()}/{topic.ToString()}";
return $"{Global.mqtt_prefix}/area{area.Number}/{topic}";
}
public static Alarm ToConfig(this clsArea area)
{
Alarm ret = new Alarm();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}";
ret.name = Global.mqtt_discovery_name_prefix + area.Name;
ret.state_topic = area.ToTopic(Topic.basic_state);
ret.command_topic = area.ToTopic(Topic.command);
Alarm ret = new Alarm
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}",
name = Global.mqtt_discovery_name_prefix + area.Name,
state_topic = area.ToTopic(Topic.basic_state),
command_topic = area.ToTopic(Topic.command)
};
return ret;
}
@ -77,89 +79,105 @@ namespace OmniLinkBridge.MQTT
public static BinarySensor ToConfigBurglary(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}burglary";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Burglary";
ret.device_class = BinarySensor.DeviceClass.safety;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}burglary",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Burglary",
device_class = BinarySensor.DeviceClass.safety,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
public static BinarySensor ToConfigFire(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}fire";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Fire";
ret.device_class = BinarySensor.DeviceClass.smoke;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.fire_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}fire",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Fire",
device_class = BinarySensor.DeviceClass.smoke,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.fire_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
public static BinarySensor ToConfigGas(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}gas";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Gas";
ret.device_class = BinarySensor.DeviceClass.gas;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.gas_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}gas",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Gas",
device_class = BinarySensor.DeviceClass.gas,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.gas_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
public static BinarySensor ToConfigAux(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}auxiliary";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Auxiliary";
ret.device_class = BinarySensor.DeviceClass.problem;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}auxiliary",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Auxiliary",
device_class = BinarySensor.DeviceClass.problem,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
public static BinarySensor ToConfigFreeze(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}freeze";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Freeze";
ret.device_class = BinarySensor.DeviceClass.cold;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.freeze_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}freeze",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Freeze",
device_class = BinarySensor.DeviceClass.cold,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.freeze_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
public static BinarySensor ToConfigWater(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}water";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Water";
ret.device_class = BinarySensor.DeviceClass.moisture;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.water_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}water",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Water",
device_class = BinarySensor.DeviceClass.moisture,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.water_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
public static BinarySensor ToConfigDuress(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}duress";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Duress";
ret.device_class = BinarySensor.DeviceClass.safety;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.duress_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}duress",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Duress",
device_class = BinarySensor.DeviceClass.safety,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.duress_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
public static BinarySensor ToConfigTemp(this clsArea area)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}temp";
ret.name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Temp";
ret.device_class = BinarySensor.DeviceClass.heat;
ret.state_topic = area.ToTopic(Topic.json_state);
ret.value_template = "{% if value_json.temperature_alarm %} ON {%- else -%} OFF {%- endif %}";
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}area{area.Number}temp",
name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Temp",
device_class = BinarySensor.DeviceClass.heat,
state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.temperature_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret;
}
@ -209,36 +227,42 @@ namespace OmniLinkBridge.MQTT
public static string ToTopic(this clsZone zone, Topic topic)
{
return $"{Global.mqtt_prefix}/zone{zone.Number.ToString()}/{topic.ToString()}";
return $"{Global.mqtt_prefix}/zone{zone.Number}/{topic}";
}
public static Sensor ToConfigTemp(this clsZone zone, enuTempFormat format)
{
Sensor ret = new Sensor();
ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}temp";
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 = (format == enuTempFormat.Fahrenheit ? "°F" : "°C");
Sensor ret = new Sensor
{
unique_id = $"{Global.mqtt_prefix}zone{zone.Number}temp",
name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp",
device_class = Sensor.DeviceClass.temperature,
state_topic = zone.ToTopic(Topic.current_temperature),
unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C")
};
return ret;
}
public static Sensor ToConfigHumidity(this clsZone zone)
{
Sensor ret = new Sensor();
ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}humidity";
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 = "%";
Sensor ret = new Sensor
{
unique_id = $"{Global.mqtt_prefix}zone{zone.Number}humidity",
name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Humidity",
device_class = Sensor.DeviceClass.humidity,
state_topic = zone.ToTopic(Topic.current_humidity),
unit_of_measurement = "%"
};
return ret;
}
public static Sensor ToConfigSensor(this clsZone zone)
{
Sensor ret = new Sensor();
ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}";
ret.name = Global.mqtt_discovery_name_prefix + zone.Name;
Sensor ret = new Sensor
{
unique_id = $"{Global.mqtt_prefix}zone{zone.Number}",
name = Global.mqtt_discovery_name_prefix + zone.Name
};
switch (zone.ZoneType)
{
@ -276,9 +300,11 @@ namespace OmniLinkBridge.MQTT
public static BinarySensor ToConfig(this clsZone zone)
{
BinarySensor ret = new BinarySensor();
ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}binary";
ret.name = Global.mqtt_discovery_name_prefix + zone.Name;
BinarySensor ret = new BinarySensor
{
unique_id = $"{Global.mqtt_prefix}zone{zone.Number}binary",
name = Global.mqtt_discovery_name_prefix + zone.Name
};
Global.mqtt_discovery_override_zone.TryGetValue(zone.Number, out OverrideZone override_zone);
@ -344,28 +370,32 @@ namespace OmniLinkBridge.MQTT
public static string ToTopic(this clsUnit unit, Topic topic)
{
return $"{Global.mqtt_prefix}/unit{unit.Number.ToString()}/{topic.ToString()}";
return $"{Global.mqtt_prefix}/unit{unit.Number}/{topic}";
}
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);
Light ret = new Light
{
unique_id = $"{Global.mqtt_prefix}unit{unit.Number}light",
name = Global.mqtt_discovery_name_prefix + unit.Name,
state_topic = unit.ToTopic(Topic.state),
command_topic = unit.ToTopic(Topic.command),
brightness_state_topic = unit.ToTopic(Topic.brightness_state),
brightness_command_topic = unit.ToTopic(Topic.brightness_command)
};
return ret;
}
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);
Switch ret = new Switch
{
unique_id = $"{Global.mqtt_prefix}unit{unit.Number}switch",
name = Global.mqtt_discovery_name_prefix + unit.Name,
state_topic = unit.ToTopic(Topic.state),
command_topic = unit.ToTopic(Topic.command)
};
return ret;
}
@ -384,30 +414,43 @@ namespace OmniLinkBridge.MQTT
return 0;
}
public static string ToSceneState(this clsUnit unit)
{
if (unit.Status >= 2 && unit.Status <= 13)
// 2-13 maps to scene A-L respectively
return ((char)(unit.Status + 63)).ToString();
return string.Empty;
}
public static string ToTopic(this clsThermostat thermostat, Topic topic)
{
return $"{Global.mqtt_prefix}/thermostat{thermostat.Number.ToString()}/{topic.ToString()}";
return $"{Global.mqtt_prefix}/thermostat{thermostat.Number}/{topic}";
}
public static Sensor ToConfigTemp(this clsThermostat thermostat, enuTempFormat format)
{
Sensor ret = new Sensor();
ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}temp";
ret.name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Temp";
ret.device_class = Sensor.DeviceClass.temperature;
ret.state_topic = thermostat.ToTopic(Topic.current_temperature);
ret.unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C");
Sensor ret = new Sensor
{
unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number}temp",
name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Temp",
device_class = Sensor.DeviceClass.temperature,
state_topic = thermostat.ToTopic(Topic.current_temperature),
unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C")
};
return ret;
}
public static Sensor ToConfigHumidity(this clsThermostat thermostat)
{
Sensor ret = new Sensor();
ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}humidity";
ret.name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Humidity";
ret.device_class = Sensor.DeviceClass.humidity;
ret.state_topic = thermostat.ToTopic(Topic.current_humidity);
ret.unit_of_measurement = "%";
Sensor ret = new Sensor
{
unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number}humidity",
name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Humidity",
device_class = Sensor.DeviceClass.humidity,
state_topic = thermostat.ToTopic(Topic.current_humidity),
unit_of_measurement = "%"
};
return ret;
}
@ -421,7 +464,7 @@ namespace OmniLinkBridge.MQTT
ret.max_temp = "35";
}
ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number.ToString()}";
ret.unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number}";
ret.name = Global.mqtt_discovery_name_prefix + thermostat.Name;
ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature);
@ -456,22 +499,24 @@ namespace OmniLinkBridge.MQTT
public static string ToTopic(this clsButton button, Topic topic)
{
return $"{Global.mqtt_prefix}/button{button.Number.ToString()}/{topic.ToString()}";
return $"{Global.mqtt_prefix}/button{button.Number}/{topic}";
}
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);
Switch ret = new Switch
{
unique_id = $"{Global.mqtt_prefix}button{button.Number}",
name = Global.mqtt_discovery_name_prefix + button.Name,
state_topic = button.ToTopic(Topic.state),
command_topic = button.ToTopic(Topic.command)
};
return ret;
}
public static string ToTopic(this clsMessage message, Topic topic)
{
return $"{Global.mqtt_prefix}/message{message.Number.ToString()}/{topic.ToString()}";
return $"{Global.mqtt_prefix}/message{message.Number}/{topic}";
}
public static string ToState(this clsMessage message)

View file

@ -116,6 +116,12 @@ namespace OmniLinkBridge.MQTT
// which will cause light to go to 100% brightness
unit.Status = (byte)(100 + unitValue);
}
else if (command == Topic.scene_command && char.TryParse(payload, out char scene))
{
log.Debug("SetUnit: {id} to {value}", unit.Number, payload);
OmniLink.SendCommand(enuUnitCommand.Compose, (byte)(scene - 63), (ushort)unit.Number);
}
}
private void ProcessThermostatReceived(clsThermostat thermostat, Topic command, string payload)

View file

@ -9,6 +9,8 @@
json_state,
brightness_state,
brightness_command,
scene_state,
scene_command,
current_operation,
current_temperature,
current_humidity,

View file

@ -33,6 +33,9 @@ namespace OmniLinkBridge.Modules
private readonly AutoResetEvent trigger = new AutoResetEvent(false);
private const string ONLINE = "online";
private const string OFFLINE = "offline";
public MQTTModule(OmniLinkII omni)
{
OmniLink = omni;
@ -53,7 +56,7 @@ namespace OmniLinkBridge.Modules
MqttApplicationMessage lastwill = new MqttApplicationMessage()
{
Topic = $"{Global.mqtt_prefix}/status",
Payload = Encoding.UTF8.GetBytes("offline"),
Payload = Encoding.UTF8.GetBytes(OFFLINE),
QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce,
Retain = true
};
@ -80,7 +83,7 @@ namespace OmniLinkBridge.Modules
{
identifiers = Global.mqtt_prefix,
name = Global.mqtt_prefix,
sw_version = $"{OmniLink.Controller.GetVersionText()} - OmniLinkBridge {Assembly.GetExecutingAssembly().GetName().Version.ToString()}",
sw_version = $"{OmniLink.Controller.GetVersionText()} - OmniLinkBridge {Assembly.GetExecutingAssembly().GetName().Version}",
model = OmniLink.Controller.GetModelText(),
manufacturer = "Leviton"
};
@ -103,6 +106,7 @@ namespace OmniLinkBridge.Modules
{
Topic.command,
Topic.brightness_command,
Topic.scene_command,
Topic.temperature_heat_command,
Topic.temperature_cool_command,
Topic.humidify_command,
@ -113,12 +117,12 @@ namespace OmniLinkBridge.Modules
};
toSubscribe.ForEach((command) => MqttClient.SubscribeAsync(
new TopicFilterBuilder().WithTopic($"{Global.mqtt_prefix}/+/{command.ToString()}").Build()));
new TopicFilterBuilder().WithTopic($"{Global.mqtt_prefix}/+/{command}").Build()));
// Wait until shutdown
trigger.WaitOne();
PublishControllerStatus("offline");
PublishControllerStatus(OFFLINE);
MqttClient.StopAsync();
}
@ -141,7 +145,7 @@ namespace OmniLinkBridge.Modules
ControllerConnected = false;
if (MqttClient.IsConnected)
PublishControllerStatus("offline");
PublishControllerStatus(OFFLINE);
}
private void PublishControllerStatus(string status)
@ -159,7 +163,7 @@ namespace OmniLinkBridge.Modules
PublishButtons();
PublishMessages();
PublishControllerStatus("online");
PublishControllerStatus(ONLINE);
PublishAsync($"{Global.mqtt_prefix}/model", OmniLink.Controller.GetModelText());
PublishAsync($"{Global.mqtt_prefix}/version", OmniLink.Controller.GetVersionText());
}
@ -177,38 +181,38 @@ namespace OmniLinkBridge.Modules
if (i > 1 && area.DefaultProperties == true)
{
PublishAsync(area.ToTopic(Topic.name), null);
PublishAsync($"{Global.mqtt_discovery_prefix}/alarm_control_panel/{Global.mqtt_prefix}/area{i.ToString()}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}burglary/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}fire/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}gas/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}aux/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}freeze/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}water/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}duress/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}temp/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/alarm_control_panel/{Global.mqtt_prefix}/area{i}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}burglary/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}fire/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}gas/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}aux/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}freeze/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}water/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}duress/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}temp/config", null);
continue;
}
PublishAreaState(area);
PublishAsync(area.ToTopic(Topic.name), area.Name);
PublishAsync($"{Global.mqtt_discovery_prefix}/alarm_control_panel/{Global.mqtt_prefix}/area{i.ToString()}/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/alarm_control_panel/{Global.mqtt_prefix}/area{i}/config",
JsonConvert.SerializeObject(area.ToConfig()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}burglary/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}burglary/config",
JsonConvert.SerializeObject(area.ToConfigBurglary()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}fire/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}fire/config",
JsonConvert.SerializeObject(area.ToConfigFire()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}gas/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}gas/config",
JsonConvert.SerializeObject(area.ToConfigGas()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}aux/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}aux/config",
JsonConvert.SerializeObject(area.ToConfigAux()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}freeze/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}freeze/config",
JsonConvert.SerializeObject(area.ToConfigFreeze()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}water/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}water/config",
JsonConvert.SerializeObject(area.ToConfigWater()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}duress/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}duress/config",
JsonConvert.SerializeObject(area.ToConfigDuress()));
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i.ToString()}temp/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/area{i}temp/config",
JsonConvert.SerializeObject(area.ToConfigTemp()));
}
}
@ -233,23 +237,23 @@ namespace OmniLinkBridge.Modules
if (zone.DefaultProperties == true || Global.mqtt_discovery_ignore_zones.Contains(zone.Number))
{
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/zone{i.ToString()}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}temp/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}humidity/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/zone{i}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}temp/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}humidity/config", null);
continue;
}
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/zone{i.ToString()}/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/binary_sensor/{Global.mqtt_prefix}/zone{i}/config",
JsonConvert.SerializeObject(zone.ToConfig()));
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}/config",
JsonConvert.SerializeObject(zone.ToConfigSensor()));
if (zone.IsTemperatureZone())
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}temp/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}temp/config",
JsonConvert.SerializeObject(zone.ToConfigTemp(OmniLink.Controller.TempFormat)));
else if (zone.IsHumidityZone())
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i.ToString()}humidity/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/zone{i}humidity/config",
JsonConvert.SerializeObject(zone.ToConfigHumidity()));
}
}
@ -275,15 +279,15 @@ namespace OmniLinkBridge.Modules
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.ToString()}/config", null);
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.ToString()}/config",
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.ToString()}/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/unit{i}/config",
JsonConvert.SerializeObject(unit.ToConfigSwitch()));
}
}
@ -299,20 +303,20 @@ namespace OmniLinkBridge.Modules
if (thermostat.DefaultProperties == true)
{
PublishAsync(thermostat.ToTopic(Topic.name), null);
PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i.ToString()}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}temp/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}humidity/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}temp/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}humidity/config", null);
continue;
}
PublishThermostatState(thermostat);
PublishAsync(thermostat.ToTopic(Topic.name), thermostat.Name);
PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i.ToString()}/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/climate/{Global.mqtt_prefix}/thermostat{i}/config",
JsonConvert.SerializeObject(thermostat.ToConfig(OmniLink.Controller.TempFormat)));
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}temp/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}temp/config",
JsonConvert.SerializeObject(thermostat.ToConfigTemp(OmniLink.Controller.TempFormat)));
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i.ToString()}humidity/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/sensor/{Global.mqtt_prefix}/thermostat{i}humidity/config",
JsonConvert.SerializeObject(thermostat.ToConfigHumidity()));
}
}
@ -328,7 +332,7 @@ namespace OmniLinkBridge.Modules
if (button.DefaultProperties == true)
{
PublishAsync(button.ToTopic(Topic.name), null);
PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i.ToString()}/config", null);
PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i}/config", null);
continue;
}
@ -336,7 +340,7 @@ namespace OmniLinkBridge.Modules
PublishAsync(button.ToTopic(Topic.state), "OFF");
PublishAsync(button.ToTopic(Topic.name), button.Name);
PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i.ToString()}/config",
PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i}/config",
JsonConvert.SerializeObject(button.ToConfig()));
}
}
@ -459,8 +463,11 @@ namespace OmniLinkBridge.Modules
{
PublishAsync(unit.ToTopic(Topic.state), unit.ToState());
if(unit.Number < 385)
if (unit.Number < 385)
{
PublishAsync(unit.ToTopic(Topic.brightness_state), unit.ToBrightnessState().ToString());
PublishAsync(unit.ToTopic(Topic.scene_state), unit.ToSceneState());
}
}
private void PublishThermostatState(clsThermostat thermostat)

View file

@ -43,7 +43,7 @@ namespace OmniLinkBridge
ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IOmniLinkService), new WebHttpBinding(), "");
host.Open();
log.Information("Listening on {url}", uri.ToString());
log.Information("Listening on {url}", uri);
}
catch (CommunicationException ex)
{

View file

@ -43,6 +43,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<NoWarn>IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
@ -52,6 +53,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<NoWarn>IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

View file

@ -82,8 +82,10 @@ namespace OmniLinkBridgeTest
"verbose_message"
})
{
List<string> lines = new List<string>(RequiredSettings());
lines.Add($"{setting} = yes");
List<string> lines = new List<string>(RequiredSettings())
{
$"{setting} = yes"
};
Settings.LoadSettings(lines.ToArray());
Assert.AreEqual(true, Global.GetValue(setting));
}
@ -193,8 +195,10 @@ namespace OmniLinkBridgeTest
"notify_message"
})
{
List<string> lines = new List<string>(RequiredSettings());
lines.Add($"{setting} = yes");
List<string> lines = new List<string>(RequiredSettings())
{
$"{setting} = yes"
};
Settings.LoadSettings(lines.ToArray());
Assert.AreEqual(true, Global.GetValue(setting));
}

View file

@ -195,6 +195,10 @@ string OFF, ON
SUB omnilink/unitX/brightness_state
PUB omnilink/unitX/brightness_command
int Level from 0 to 100 percent
SUB omnilink/unitX/scene_state
PUB omnilink/unitX/scene_command
string A-L
```
### Thermostats