mirror of
https://github.com/excaliburpartners/OmniLinkBridge
synced 2024-12-22 10:42:24 +00:00
1.1.17 - Add MQTT volume scaling for Home Assistant media player
This commit is contained in:
parent
73f504ca93
commit
d7eef51adf
|
@ -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;
|
||||||
|
|
|
@ -16,5 +16,8 @@ namespace OmniLinkBridge.MQTT.HomeAssistant
|
||||||
|
|
||||||
[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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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")]
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue