mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 03:14:07 +01:00
Add UoM support for volume dB channel (#16759)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
e18c9b39c4
commit
eae7b645ab
@ -52,25 +52,25 @@ The DenonMarantz AVR supports the following channels (some channels are model sp
|
|||||||
| _Main zone_ | |
|
| _Main zone_ | |
|
||||||
| mainZone#power | Switch (RW) | Main zone power on/off
|
| mainZone#power | Switch (RW) | Main zone power on/off
|
||||||
| mainZone#volume | Dimmer (RW) | Main zone volume
|
| mainZone#volume | Dimmer (RW) | Main zone volume
|
||||||
| mainZone#volumeDB | Number (RW) | Main zone volume in dB (-80 offset)
|
| mainZone#volumeDB | Number:Dimensionless (RW) | Main zone volume in dB (-80 offset)
|
||||||
| mainZone#mute | Switch (RW) | Main zone mute
|
| mainZone#mute | Switch (RW) | Main zone mute
|
||||||
| mainZone#input | String (RW) | Main zone input (e.g. TV, TUNER, ..)
|
| mainZone#input | String (RW) | Main zone input (e.g. TV, TUNER, ..)
|
||||||
| _Zone 2_ | |
|
| _Zone 2_ | |
|
||||||
| zone2#power | Switch (RW) | Zone 2 power on/off
|
| zone2#power | Switch (RW) | Zone 2 power on/off
|
||||||
| zone2#volume | Dimmer (RW) | Zone 2 volume
|
| zone2#volume | Dimmer (RW) | Zone 2 volume
|
||||||
| zone2#volumeDB | Number (RW) | Zone 2 volume in dB (-80 offset)
|
| zone2#volumeDB | Number:Dimensionless (RW) | Zone 2 volume in dB (-80 offset)
|
||||||
| zone2#mute | Switch (RW) | Zone 2 mute
|
| zone2#mute | Switch (RW) | Zone 2 mute
|
||||||
| zone2#input | String (RW) | Zone 2 input
|
| zone2#input | String (RW) | Zone 2 input
|
||||||
| _Zone 3_ | |
|
| _Zone 3_ | |
|
||||||
| zone3#power | Switch (RW) | Zone 3 power on/off
|
| zone3#power | Switch (RW) | Zone 3 power on/off
|
||||||
| zone3#volume | Dimmer (RW) | Zone 3 volume
|
| zone3#volume | Dimmer (RW) | Zone 3 volume
|
||||||
| zone3#volumeDB | Number (RW) | Zone 3 volume in dB (-80 offset)
|
| zone3#volumeDB | Number:Dimensionless (RW) | Zone 3 volume in dB (-80 offset)
|
||||||
| zone3#mute | Switch (RW) | Zone 3 mute
|
| zone3#mute | Switch (RW) | Zone 3 mute
|
||||||
| zone3#input | String (RW) | Zone 3 input
|
| zone3#input | String (RW) | Zone 3 input
|
||||||
| _Zone 4_ | |
|
| _Zone 4_ | |
|
||||||
| zone4#power | Switch (RW) | Zone 4 power on/off
|
| zone4#power | Switch (RW) | Zone 4 power on/off
|
||||||
| zone4#volume | Dimmer (RW) | Zone 4 volume
|
| zone4#volume | Dimmer (RW) | Zone 4 volume
|
||||||
| zone4#volumeDB | Number (RW) | Zone 4 volume in dB (-80 offset)
|
| zone4#volumeDB | Number:Dimensionless (RW) | Zone 4 volume in dB (-80 offset)
|
||||||
| zone4#mute | Switch (RW) | Zone 4 mute
|
| zone4#mute | Switch (RW) | Zone 4 mute
|
||||||
| zone4#input | String (RW) | Zone 4 input
|
| zone4#input | String (RW) | Zone 4 input
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ Thing denonmarantz:avr:1 "Receiver" @ "Living room" [host="192.168.1.100"]
|
|||||||
```java
|
```java
|
||||||
Switch marantz_power "Receiver" <switch> {channel="denonmarantz:avr:1:general#power"}
|
Switch marantz_power "Receiver" <switch> {channel="denonmarantz:avr:1:general#power"}
|
||||||
Dimmer marantz_volume "Volume" <soundvolume> {channel="denonmarantz:avr:1:mainZone#volume"}
|
Dimmer marantz_volume "Volume" <soundvolume> {channel="denonmarantz:avr:1:mainZone#volume"}
|
||||||
Number marantz_volumeDB "Volume [%.1f dB]" {channel="denonmarantz:avr:1:mainzone#volume"}
|
Number:Dimensionless marantz_volumeDB "Volume [%.1f dB]" {channel="denonmarantz:avr:1:mainzone#volume", unit="dB"}
|
||||||
Switch marantz_mute "Mute" <mute> {channel="denonmarantz:avr:1:mainZone#mute"}
|
Switch marantz_mute "Mute" <mute> {channel="denonmarantz:avr:1:mainZone#mute"}
|
||||||
Switch marantz_z2power "Zone 2" {channel="denonmarantz:avr:1:zone2#power"}
|
Switch marantz_z2power "Zone 2" {channel="denonmarantz:avr:1:zone2#power"}
|
||||||
String marantz_input "Input [%s]" {channel="denonmarantz:avr:1:mainZone#input" }
|
String marantz_input "Input [%s]" {channel="denonmarantz:avr:1:mainZone#input" }
|
||||||
|
@ -16,10 +16,11 @@ import java.math.BigDecimal;
|
|||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.core.library.types.DecimalType;
|
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.library.types.PercentType;
|
import org.openhab.core.library.types.PercentType;
|
||||||
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
|
import org.openhab.core.library.unit.Units;
|
||||||
import org.openhab.core.types.State;
|
import org.openhab.core.types.State;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,8 +165,8 @@ public class DenonMarantzState {
|
|||||||
this.mainVolume = newVal;
|
this.mainVolume = newVal;
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_MAIN_VOLUME, newVal);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_MAIN_VOLUME, newVal);
|
||||||
// update the main volume in dB too
|
// update the main volume in dB too
|
||||||
State mainVolumeDB = this.mainVolumeDB = DecimalType
|
State mainVolumeDB = this.mainVolumeDB = new QuantityType<>(
|
||||||
.valueOf(volume.subtract(DenonMarantzBindingConstants.DB_OFFSET).toString());
|
volume.subtract(DenonMarantzBindingConstants.DB_OFFSET), Units.DECIBEL);
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_MAIN_VOLUME_DB, mainVolumeDB);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_MAIN_VOLUME_DB, mainVolumeDB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,8 +225,8 @@ public class DenonMarantzState {
|
|||||||
this.zone2Volume = newVal;
|
this.zone2Volume = newVal;
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE2_VOLUME, newVal);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE2_VOLUME, newVal);
|
||||||
// update the volume in dB too
|
// update the volume in dB too
|
||||||
State zone2VolumeDB = this.zone2VolumeDB = DecimalType
|
State zone2VolumeDB = this.zone2VolumeDB = new QuantityType<>(
|
||||||
.valueOf(volume.subtract(DenonMarantzBindingConstants.DB_OFFSET).toString());
|
volume.subtract(DenonMarantzBindingConstants.DB_OFFSET), Units.DECIBEL);
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE2_VOLUME_DB, zone2VolumeDB);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE2_VOLUME_DB, zone2VolumeDB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -260,8 +261,8 @@ public class DenonMarantzState {
|
|||||||
this.zone3Volume = newVal;
|
this.zone3Volume = newVal;
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE3_VOLUME, newVal);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE3_VOLUME, newVal);
|
||||||
// update the volume in dB too
|
// update the volume in dB too
|
||||||
State zone3VolumeDB = this.zone3VolumeDB = DecimalType
|
State zone3VolumeDB = this.zone3VolumeDB = new QuantityType<>(
|
||||||
.valueOf(volume.subtract(DenonMarantzBindingConstants.DB_OFFSET).toString());
|
volume.subtract(DenonMarantzBindingConstants.DB_OFFSET), Units.DECIBEL);
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE3_VOLUME_DB, zone3VolumeDB);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE3_VOLUME_DB, zone3VolumeDB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -296,8 +297,8 @@ public class DenonMarantzState {
|
|||||||
this.zone4Volume = newVal;
|
this.zone4Volume = newVal;
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE4_VOLUME, newVal);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE4_VOLUME, newVal);
|
||||||
// update the volume in dB too
|
// update the volume in dB too
|
||||||
State zone4VolumeDB = this.zone4VolumeDB = DecimalType
|
State zone4VolumeDB = this.zone4VolumeDB = new QuantityType<>(
|
||||||
.valueOf(volume.subtract(DenonMarantzBindingConstants.DB_OFFSET).toString());
|
volume.subtract(DenonMarantzBindingConstants.DB_OFFSET), Units.DECIBEL);
|
||||||
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE4_VOLUME_DB, zone4VolumeDB);
|
handler.stateChanged(DenonMarantzBindingConstants.CHANNEL_ZONE4_VOLUME_DB, zone4VolumeDB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,9 @@ import org.openhab.core.library.types.DecimalType;
|
|||||||
import org.openhab.core.library.types.IncreaseDecreaseType;
|
import org.openhab.core.library.types.IncreaseDecreaseType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
import org.openhab.core.library.types.PercentType;
|
import org.openhab.core.library.types.PercentType;
|
||||||
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
|
import org.openhab.core.library.unit.Units;
|
||||||
import org.openhab.core.types.Command;
|
import org.openhab.core.types.Command;
|
||||||
import org.openhab.core.types.RefreshType;
|
import org.openhab.core.types.RefreshType;
|
||||||
|
|
||||||
@ -188,9 +190,16 @@ public abstract class DenonMarantzConnector {
|
|||||||
Command dbCommand = command;
|
Command dbCommand = command;
|
||||||
if (dbCommand instanceof PercentType) {
|
if (dbCommand instanceof PercentType) {
|
||||||
throw new UnsupportedCommandTypeException();
|
throw new UnsupportedCommandTypeException();
|
||||||
} else if (dbCommand instanceof DecimalType) {
|
} else if (dbCommand instanceof DecimalType decimalCommand) {
|
||||||
// convert dB to 'normal' volume by adding the offset of 80
|
// convert dB to 'normal' volume by adding the offset of 80
|
||||||
dbCommand = new DecimalType(((DecimalType) command).toBigDecimal().add(DB_OFFSET));
|
dbCommand = new DecimalType(decimalCommand.toBigDecimal().add(DB_OFFSET));
|
||||||
|
} else if (dbCommand instanceof QuantityType<?> quantityCommand) {
|
||||||
|
QuantityType<?> decibelCommand = quantityCommand.toUnit(Units.DECIBEL);
|
||||||
|
if (decibelCommand != null) {
|
||||||
|
dbCommand = new DecimalType(new BigDecimal(decibelCommand.doubleValue()).add(DB_OFFSET));
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedCommandTypeException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sendVolumeCommand(dbCommand, zone);
|
sendVolumeCommand(dbCommand, zone);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
|||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps Denon volume values in db to percentage
|
* Maps Denon volume values in dB to percentage
|
||||||
*
|
*
|
||||||
* @author Jeroen Idserda - Initial contribution
|
* @author Jeroen Idserda - Initial contribution
|
||||||
*/
|
*/
|
||||||
|
@ -29,6 +29,10 @@
|
|||||||
</channel-group>
|
</channel-group>
|
||||||
</channel-groups>
|
</channel-groups>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<property name="thingTypeVersion">1</property>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<representation-property>serialNumber</representation-property>
|
<representation-property>serialNumber</representation-property>
|
||||||
|
|
||||||
<config-description>
|
<config-description>
|
||||||
@ -138,11 +142,11 @@
|
|||||||
</channel-type>
|
</channel-type>
|
||||||
|
|
||||||
<channel-type id="volumeDB" advanced="true">
|
<channel-type id="volumeDB" advanced="true">
|
||||||
<item-type>Number</item-type>
|
<item-type unitHint="dB">Number:Dimensionless</item-type>
|
||||||
<label>Volume (dB)</label>
|
<label>Volume (dB)</label>
|
||||||
<description>Set the volume level (dB). Same as [mainVolume - 80].</description>
|
<description>Set the volume level (dB). Same as [mainVolume - 80].</description>
|
||||||
<category>SoundVolume</category>
|
<category>SoundVolume</category>
|
||||||
<state min="-80" max="18" step="0.5" pattern="%.1f dB"/>
|
<state min="-80" max="18" step="0.5" pattern="%.1f %unit%"/>
|
||||||
</channel-type>
|
</channel-type>
|
||||||
|
|
||||||
<channel-type id="mute">
|
<channel-type id="mute">
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
|
||||||
|
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
|
||||||
|
|
||||||
|
<thing-type uid="denonmarantz:avr">
|
||||||
|
|
||||||
|
<instruction-set targetVersion="1">
|
||||||
|
<update-channel id="volumeDB" groupIds="mainZone,zone2,zone3,zone4">
|
||||||
|
<type>denonmarantz:volumeDB</type>
|
||||||
|
</update-channel>
|
||||||
|
</instruction-set>
|
||||||
|
|
||||||
|
</thing-type>
|
||||||
|
|
||||||
|
</update:update-descriptions>
|
Loading…
Reference in New Issue
Block a user