1.1.17 - Add MQTT volume scaling for Home Assistant media player

This commit is contained in:
Ryan Wagoner 2024-05-05 15:33:24 -04:00
parent 73f504ca93
commit d7eef51adf
9 changed files with 46 additions and 9 deletions

View file

@ -62,6 +62,7 @@ namespace OmniLinkBridge
public static ConcurrentDictionary<int, MQTT.OverrideUnit> mqtt_discovery_override_unit; public static ConcurrentDictionary<int, MQTT.OverrideUnit> mqtt_discovery_override_unit;
public static Type mqtt_discovery_button_type; public static Type mqtt_discovery_button_type;
public static bool mqtt_audio_local_mute; public static bool mqtt_audio_local_mute;
public static bool mqtt_audio_volume_media_player;
// Notifications // Notifications
public static bool notify_area; public static bool notify_area;

View file

@ -12,9 +12,12 @@ namespace OmniLinkBridge.MQTT.HomeAssistant
public string command_topic { get; set; } public string command_topic { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)] [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int? min { get; set; } public int? min { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)] [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int? max { get; set; } public int? max { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public double? step { get; set; }
} }
} }

View file

@ -726,13 +726,27 @@ namespace OmniLinkBridge.MQTT
icon = "mdi:volume-low", icon = "mdi:volume-low",
state_topic = audioZone.ToTopic(Topic.volume_state), state_topic = audioZone.ToTopic(Topic.volume_state),
command_topic = audioZone.ToTopic(Topic.volume_command), command_topic = audioZone.ToTopic(Topic.volume_command),
min = 0,
max = 100,
step = 1,
}; };
if(Global.mqtt_audio_volume_media_player)
{
ret.min = 0;
ret.max = 1;
ret.step = 0.01;
}
return ret; return ret;
} }
public static int ToVolumeState(this clsAudioZone audioZone) public static double ToVolumeState(this clsAudioZone audioZone)
{ {
return audioZone.Volume; if (Global.mqtt_audio_volume_media_player)
return audioZone.Volume * 0.01;
else
return audioZone.Volume;
} }
} }
} }

View file

@ -397,9 +397,17 @@ namespace OmniLinkBridge.MQTT
OmniLink.SendCommand(enuUnitCommand.AudioSource, (byte)source, (ushort)audioZone.Number); OmniLink.SendCommand(enuUnitCommand.AudioSource, (byte)source, (ushort)audioZone.Number);
} }
else if (command == Topic.volume_command && int.TryParse(payload, out int volume)) else if (command == Topic.volume_command && double.TryParse(payload, out double volume))
{ {
log.Debug("SetAudioVolume: {id} to {value}", audioZone.Number, payload); if (Global.mqtt_audio_volume_media_player)
volume *= 100;
if (volume > 100)
volume = 100;
else if (volume < 0)
volume = 0;
log.Debug("SetAudioVolume: {id} to {value}", audioZone.Number, volume);
OmniLink.SendCommand(enuUnitCommand.AudioVolume, (byte)volume, (ushort)audioZone.Number); OmniLink.SendCommand(enuUnitCommand.AudioVolume, (byte)volume, (ushort)audioZone.Number);
} }

View file

@ -70,10 +70,13 @@ mqtt_discovery_area_code_required =
#mqtt_discovery_override_unit = id=1;type=switch #mqtt_discovery_override_unit = id=1;type=switch
#mqtt_discovery_override_unit = id=395;type=number #mqtt_discovery_override_unit = id=395;type=number
# Publish buttons as this Home Assistant device type # Publish buttons as this Home Assistant device type
# must be button or switch (previous behavior) # must be button (recommended) or switch (default, previous behavior)
#mqtt_discovery_button_type = button mqtt_discovery_button_type = switch
# Handle mute locally by setting volume to 0 and restoring to previous value # Handle mute locally by setting volume to 0 and restoring to previous value
mqtt_audio_local_mute = no mqtt_audio_local_mute = no
# Change audio volume scaling for Home Assistant media player
# yes 0.00-1.00, no 0-100 (default, previous behavior)
mqtt_audio_volume_media_player = no
# Notifications (yes/no) # Notifications (yes/no)
# Always sent for area alarms and critical system events # Always sent for area alarms and critical system events

View file

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.16.0")] [assembly: AssemblyVersion("1.1.17.0")]
[assembly: AssemblyFileVersion("1.1.16.0")] [assembly: AssemblyFileVersion("1.1.17.0")]

View file

@ -93,6 +93,7 @@ namespace OmniLinkBridge
Global.mqtt_discovery_override_unit = settings.LoadOverrideUnit<MQTT.OverrideUnit>("mqtt_discovery_override_unit"); Global.mqtt_discovery_override_unit = settings.LoadOverrideUnit<MQTT.OverrideUnit>("mqtt_discovery_override_unit");
Global.mqtt_discovery_button_type = settings.ValidateType("mqtt_discovery_button_type", typeof(Switch), typeof(Button)); Global.mqtt_discovery_button_type = settings.ValidateType("mqtt_discovery_button_type", typeof(Switch), typeof(Button));
Global.mqtt_audio_local_mute = settings.ValidateBool("mqtt_audio_local_mute"); Global.mqtt_audio_local_mute = settings.ValidateBool("mqtt_audio_local_mute");
Global.mqtt_audio_volume_media_player = settings.ValidateBool("mqtt_audio_volume_media_player");
} }
// Notifications // Notifications

View file

@ -433,6 +433,12 @@ namespace OmniLinkBridgeTest
check(1, "75", enuUnitCommand.AudioVolume, 75); check(1, "75", enuUnitCommand.AudioVolume, 75);
check(2, "0", enuUnitCommand.AudioVolume, 0); check(2, "0", enuUnitCommand.AudioVolume, 0);
Global.mqtt_audio_volume_media_player = true;
check(2, "1", enuUnitCommand.AudioVolume, 100);
check(2, "0.75", enuUnitCommand.AudioVolume, 75);
check(2, "0", enuUnitCommand.AudioVolume, 0);
} }
} }
} }

View file

@ -355,6 +355,7 @@ note Refer to omnilink/sourceXX/name
SUB omnilink/audioXX/volume_state SUB omnilink/audioXX/volume_state
PUB omnilink/audioXX/volume_command PUB omnilink/audioXX/volume_command
int Level from 0 to 100 percent int Level from 0 to 100 percent
double Level from 0.00 to 1.00 (mqtt_audio_volume_media_player = yes)
``` ```
## Web API ## Web API