|
|
|
@ -12,9 +12,11 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
{
|
|
|
|
|
public class CurrentVolumeSensor : AbstractSensor
|
|
|
|
|
{
|
|
|
|
|
private MMDeviceEnumerator DevEnum;
|
|
|
|
|
private MMDeviceEnumerator deviceEnumerator;
|
|
|
|
|
private MMDeviceCollection devices;
|
|
|
|
|
public CurrentVolumeSensor(MqttPublisher publisher, int? updateInterval = null, string name = "CurrentVolume", Guid id = default(Guid)) : base(publisher, name ?? "CurrentVolume", updateInterval ?? 10, id) {
|
|
|
|
|
this.DevEnum = new MMDeviceEnumerator();
|
|
|
|
|
this.deviceEnumerator = new MMDeviceEnumerator();
|
|
|
|
|
this.devices = deviceEnumerator.EnumerateAudioEndPoints(EDataFlow.eRender, DEVICE_STATE.DEVICE_STATE_ACTIVE);
|
|
|
|
|
}
|
|
|
|
|
public override SensorDiscoveryConfigModel GetAutoDiscoveryConfig()
|
|
|
|
|
{
|
|
|
|
@ -30,17 +32,11 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[DllImport("winmm.dll")]
|
|
|
|
|
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
|
|
|
|
|
|
|
|
|
|
public override string GetState()
|
|
|
|
|
{
|
|
|
|
|
var collection = DevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, DEVICE_STATE.DEVICE_STATE_ACTIVE);
|
|
|
|
|
|
|
|
|
|
List<float> peaks = new List<float>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (MMDevice device in collection)
|
|
|
|
|
foreach (MMDevice device in devices)
|
|
|
|
|
{
|
|
|
|
|
peaks.Add(device.AudioMeterInformation.PeakValues[0]);
|
|
|
|
|
}
|
|
|
|
|