- 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) 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) public static Alarm ToConfig(this clsArea area)
{ {
Alarm ret = new Alarm(); Alarm ret = new Alarm
ret.unique_id = $"{Global.mqtt_prefix}area{area.Number.ToString()}"; {
ret.name = Global.mqtt_discovery_name_prefix + area.Name; unique_id = $"{Global.mqtt_prefix}area{area.Number}",
ret.state_topic = area.ToTopic(Topic.basic_state); name = Global.mqtt_discovery_name_prefix + area.Name,
ret.command_topic = area.ToTopic(Topic.command); state_topic = area.ToTopic(Topic.basic_state),
command_topic = area.ToTopic(Topic.command)
};
return ret; return ret;
} }
@ -77,89 +79,105 @@ namespace OmniLinkBridge.MQTT
public static BinarySensor ToConfigBurglary(this clsArea area) public static BinarySensor ToConfigBurglary(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}burglary",
ret.device_class = BinarySensor.DeviceClass.safety; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Burglary",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.safety,
ret.value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
public static BinarySensor ToConfigFire(this clsArea area) public static BinarySensor ToConfigFire(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}fire",
ret.device_class = BinarySensor.DeviceClass.smoke; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Fire",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.smoke,
ret.value_template = "{% if value_json.fire_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.fire_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
public static BinarySensor ToConfigGas(this clsArea area) public static BinarySensor ToConfigGas(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}gas",
ret.device_class = BinarySensor.DeviceClass.gas; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Gas",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.gas,
ret.value_template = "{% if value_json.gas_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.gas_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
public static BinarySensor ToConfigAux(this clsArea area) public static BinarySensor ToConfigAux(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}auxiliary",
ret.device_class = BinarySensor.DeviceClass.problem; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Auxiliary",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.problem,
ret.value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.burglary_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
public static BinarySensor ToConfigFreeze(this clsArea area) public static BinarySensor ToConfigFreeze(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}freeze",
ret.device_class = BinarySensor.DeviceClass.cold; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Freeze",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.cold,
ret.value_template = "{% if value_json.freeze_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.freeze_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
public static BinarySensor ToConfigWater(this clsArea area) public static BinarySensor ToConfigWater(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}water",
ret.device_class = BinarySensor.DeviceClass.moisture; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Water",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.moisture,
ret.value_template = "{% if value_json.water_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.water_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
public static BinarySensor ToConfigDuress(this clsArea area) public static BinarySensor ToConfigDuress(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}duress",
ret.device_class = BinarySensor.DeviceClass.safety; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Duress",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.safety,
ret.value_template = "{% if value_json.duress_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.duress_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
public static BinarySensor ToConfigTemp(this clsArea area) public static BinarySensor ToConfigTemp(this clsArea area)
{ {
BinarySensor ret = new BinarySensor(); 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"; unique_id = $"{Global.mqtt_prefix}area{area.Number}temp",
ret.device_class = BinarySensor.DeviceClass.heat; name = $"{Global.mqtt_discovery_name_prefix}{area.Name} Temp",
ret.state_topic = area.ToTopic(Topic.json_state); device_class = BinarySensor.DeviceClass.heat,
ret.value_template = "{% if value_json.temperature_alarm %} ON {%- else -%} OFF {%- endif %}"; state_topic = area.ToTopic(Topic.json_state),
value_template = "{% if value_json.temperature_alarm %} ON {%- else -%} OFF {%- endif %}"
};
return ret; return ret;
} }
@ -209,36 +227,42 @@ namespace OmniLinkBridge.MQTT
public static string ToTopic(this clsZone zone, Topic topic) 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) public static Sensor ToConfigTemp(this clsZone zone, enuTempFormat format)
{ {
Sensor ret = new Sensor(); 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"; unique_id = $"{Global.mqtt_prefix}zone{zone.Number}temp",
ret.device_class = Sensor.DeviceClass.temperature; name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Temp",
ret.state_topic = zone.ToTopic(Topic.current_temperature); device_class = Sensor.DeviceClass.temperature,
ret.unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C"); state_topic = zone.ToTopic(Topic.current_temperature),
unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C")
};
return ret; return ret;
} }
public static Sensor ToConfigHumidity(this clsZone zone) public static Sensor ToConfigHumidity(this clsZone zone)
{ {
Sensor ret = new Sensor(); 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"; unique_id = $"{Global.mqtt_prefix}zone{zone.Number}humidity",
ret.device_class = Sensor.DeviceClass.humidity; name = $"{Global.mqtt_discovery_name_prefix}{zone.Name} Humidity",
ret.state_topic = zone.ToTopic(Topic.current_humidity); device_class = Sensor.DeviceClass.humidity,
ret.unit_of_measurement = "%"; state_topic = zone.ToTopic(Topic.current_humidity),
unit_of_measurement = "%"
};
return ret; return ret;
} }
public static Sensor ToConfigSensor(this clsZone zone) public static Sensor ToConfigSensor(this clsZone zone)
{ {
Sensor ret = new Sensor(); Sensor ret = new Sensor
ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}"; {
ret.name = Global.mqtt_discovery_name_prefix + zone.Name; unique_id = $"{Global.mqtt_prefix}zone{zone.Number}",
name = Global.mqtt_discovery_name_prefix + zone.Name
};
switch (zone.ZoneType) switch (zone.ZoneType)
{ {
@ -276,9 +300,11 @@ namespace OmniLinkBridge.MQTT
public static BinarySensor ToConfig(this clsZone zone) public static BinarySensor ToConfig(this clsZone zone)
{ {
BinarySensor ret = new BinarySensor(); BinarySensor ret = new BinarySensor
ret.unique_id = $"{Global.mqtt_prefix}zone{zone.Number.ToString()}binary"; {
ret.name = Global.mqtt_discovery_name_prefix + zone.Name; 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); 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) 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) public static Light ToConfig(this clsUnit unit)
{ {
Light ret = new Light(); Light ret = new Light
ret.unique_id = $"{Global.mqtt_prefix}unit{unit.Number.ToString()}light"; {
ret.name = Global.mqtt_discovery_name_prefix + unit.Name; unique_id = $"{Global.mqtt_prefix}unit{unit.Number}light",
ret.state_topic = unit.ToTopic(Topic.state); name = Global.mqtt_discovery_name_prefix + unit.Name,
ret.command_topic = unit.ToTopic(Topic.command); state_topic = unit.ToTopic(Topic.state),
ret.brightness_state_topic = unit.ToTopic(Topic.brightness_state); command_topic = unit.ToTopic(Topic.command),
ret.brightness_command_topic = unit.ToTopic(Topic.brightness_command); brightness_state_topic = unit.ToTopic(Topic.brightness_state),
brightness_command_topic = unit.ToTopic(Topic.brightness_command)
};
return ret; return ret;
} }
public static Switch ToConfigSwitch(this clsUnit unit) public static Switch ToConfigSwitch(this clsUnit unit)
{ {
Switch ret = new Switch(); Switch ret = new Switch
ret.unique_id = $"{Global.mqtt_prefix}unit{unit.Number.ToString()}switch"; {
ret.name = Global.mqtt_discovery_name_prefix + unit.Name; unique_id = $"{Global.mqtt_prefix}unit{unit.Number}switch",
ret.state_topic = unit.ToTopic(Topic.state); name = Global.mqtt_discovery_name_prefix + unit.Name,
ret.command_topic = unit.ToTopic(Topic.command); state_topic = unit.ToTopic(Topic.state),
command_topic = unit.ToTopic(Topic.command)
};
return ret; return ret;
} }
@ -384,30 +414,43 @@ namespace OmniLinkBridge.MQTT
return 0; 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) 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) public static Sensor ToConfigTemp(this clsThermostat thermostat, enuTempFormat format)
{ {
Sensor ret = new Sensor(); 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"; unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number}temp",
ret.device_class = Sensor.DeviceClass.temperature; name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Temp",
ret.state_topic = thermostat.ToTopic(Topic.current_temperature); device_class = Sensor.DeviceClass.temperature,
ret.unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C"); state_topic = thermostat.ToTopic(Topic.current_temperature),
unit_of_measurement = (format == enuTempFormat.Fahrenheit ? "°F" : "°C")
};
return ret; return ret;
} }
public static Sensor ToConfigHumidity(this clsThermostat thermostat) public static Sensor ToConfigHumidity(this clsThermostat thermostat)
{ {
Sensor ret = new Sensor(); 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"; unique_id = $"{Global.mqtt_prefix}thermostat{thermostat.Number}humidity",
ret.device_class = Sensor.DeviceClass.humidity; name = $"{Global.mqtt_discovery_name_prefix}{thermostat.Name} Humidity",
ret.state_topic = thermostat.ToTopic(Topic.current_humidity); device_class = Sensor.DeviceClass.humidity,
ret.unit_of_measurement = "%"; state_topic = thermostat.ToTopic(Topic.current_humidity),
unit_of_measurement = "%"
};
return ret; return ret;
} }
@ -421,7 +464,7 @@ namespace OmniLinkBridge.MQTT
ret.max_temp = "35"; 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.name = Global.mqtt_discovery_name_prefix + thermostat.Name;
ret.current_temperature_topic = thermostat.ToTopic(Topic.current_temperature); 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) 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) public static Switch ToConfig(this clsButton button)
{ {
Switch ret = new Switch(); Switch ret = new Switch
ret.unique_id = $"{Global.mqtt_prefix}button{button.Number.ToString()}"; {
ret.name = Global.mqtt_discovery_name_prefix + button.Name; unique_id = $"{Global.mqtt_prefix}button{button.Number}",
ret.state_topic = button.ToTopic(Topic.state); name = Global.mqtt_discovery_name_prefix + button.Name,
ret.command_topic = button.ToTopic(Topic.command); state_topic = button.ToTopic(Topic.state),
command_topic = button.ToTopic(Topic.command)
};
return ret; return ret;
} }
public static string ToTopic(this clsMessage message, Topic topic) 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) 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 // which will cause light to go to 100% brightness
unit.Status = (byte)(100 + unitValue); 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) private void ProcessThermostatReceived(clsThermostat thermostat, Topic command, string payload)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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