]> git.basschouten.com Git - openhab-addons.git/commitdiff
[amplipi] Add new power channel to zones and groups (#16171)
authorKai Kreuzer <kai@openhab.org>
Tue, 2 Jan 2024 21:29:18 +0000 (22:29 +0100)
committerGitHub <noreply@github.com>
Tue, 2 Jan 2024 21:29:18 +0000 (22:29 +0100)
* [amplipi] Add new power channel to zones and groups

Signed-off-by: Kai Kreuzer <kai@openhab.org>
bundles/org.openhab.binding.amplipi/README.md
bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiBindingConstants.java
bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiGroupHandler.java
bundles/org.openhab.binding.amplipi/src/main/java/org/openhab/binding/amplipi/internal/AmpliPiZoneHandler.java
bundles/org.openhab.binding.amplipi/src/main/resources/OH-INF/thing/thing-types.xml
bundles/org.openhab.binding.amplipi/src/main/resources/OH-INF/update/binding.xml [new file with mode: 0644]

index ad4d28adf61fb83f00c6b02d4e56ec208245b679..30a63aad8730f454a94de747d368fc25ef736231 100644 (file)
@@ -40,6 +40,7 @@ The `zone` and `group` Things have the following channels:
 
 | Channel  | Type   | Description                                        |
 |----------|--------|----------------------------------------------------|
+| power    | Switch | Whether the zone/group is active or off            |
 | volume   | Dimmer | The volume of the zone/group                       |
 | mute     | Switch | Mutes the zone/group                               |
 | source   | Number | The source (1-4) that this zone/group is playing   |
@@ -70,6 +71,7 @@ String      Input2      "Input 2"               { channel="amplipi:controller:1:
 String      Input3      "Input 3"               { channel="amplipi:controller:1:input3" }
 String      Input4      "Input 4"               { channel="amplipi:controller:1:input4" }
 
+Switch      PowerZ2     "Power Zone2"           { channel="amplipi:zone:1:zone2:power" }
 Dimmer      VolumeZ2    "Volume Zone2"          { channel="amplipi:zone:1:zone2:volume" }
 Switch      MuteZ2      "Mute Zone2"            { channel="amplipi:zone:1:zone2::mute" }
 Number      SourceZ2    "Source Zone2"          { channel="amplipi:zone:1:zone2::source" }
@@ -88,6 +90,7 @@ sitemap amplipi label="Main Menu"
         Selection item=Input4
     }
     Frame label="Living Room Zone" {
+        Switch item=PowerZ2
         Slider item=VolumeZ2 label="Volume Zone 1 [%.1f %%]"
         Switch item=MuteZ2
         Selection item=SourceZ2
index fafbfd0d1b945ae6c91b066c8d022581532f615c..89ee54398349686c738b3e821f1b46d0526b551c 100644 (file)
@@ -34,6 +34,7 @@ public class AmpliPiBindingConstants {
     // List of all Channel ids
     public static final String CHANNEL_PRESET = "preset";
     public static final String CHANNEL_INPUT = "input";
+    public static final String CHANNEL_POWER = "power";
     public static final String CHANNEL_VOLUME = "volume";
     public static final String CHANNEL_MUTE = "mute";
     public static final String CHANNEL_SOURCE = "source";
index 0f32129d8d420811afbbbb7cf28a4ac026183f75..14fd3f188d25e26386494dc2ece090bf677f02d7 100644 (file)
@@ -103,6 +103,11 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat
         }
         GroupUpdate update = new GroupUpdate();
         switch (channelUID.getId()) {
+            case AmpliPiBindingConstants.CHANNEL_POWER:
+                if (command instanceof OnOffType) {
+                    update.setMute(command == OnOffType.OFF);
+                }
+                break;
             case AmpliPiBindingConstants.CHANNEL_MUTE:
                 if (command instanceof OnOffType) {
                     update.setMute(command == OnOffType.ON);
@@ -159,10 +164,12 @@ public class AmpliPiGroupHandler extends BaseThingHandler implements AmpliPiStat
     private void updateGroupState(Group state) {
         this.groupState = state;
 
+        Boolean power = !groupState.getMute();
         Boolean mute = groupState.getMute();
         Integer volDelta = groupState.getVolDelta();
         Integer sourceId = groupState.getSourceId();
 
+        updateState(AmpliPiBindingConstants.CHANNEL_POWER, OnOffType.from(power));
         updateState(AmpliPiBindingConstants.CHANNEL_MUTE, OnOffType.from(mute));
         updateState(AmpliPiBindingConstants.CHANNEL_VOLUME, AmpliPiUtils.volumeToPercentType(volDelta));
         updateState(AmpliPiBindingConstants.CHANNEL_SOURCE, new DecimalType(sourceId));
index 870a9af3f759f138ad872cfacb95de14554bbb29..e7c85c8f324fcc06a909c81c325c2fab15bee5b1 100644 (file)
@@ -103,6 +103,11 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu
         }
         ZoneUpdate update = new ZoneUpdate();
         switch (channelUID.getId()) {
+            case AmpliPiBindingConstants.CHANNEL_POWER:
+                if (command instanceof OnOffType) {
+                    update.setMute(command == OnOffType.OFF);
+                }
+                break;
             case AmpliPiBindingConstants.CHANNEL_MUTE:
                 if (command instanceof OnOffType) {
                     update.setMute(command == OnOffType.ON);
@@ -159,10 +164,12 @@ public class AmpliPiZoneHandler extends BaseThingHandler implements AmpliPiStatu
     private void updateZoneState(Zone state) {
         this.zoneState = state;
 
+        Boolean power = !zoneState.getMute();
         Boolean mute = zoneState.getMute();
         Integer vol = zoneState.getVol();
         Integer sourceId = zoneState.getSourceId();
 
+        updateState(AmpliPiBindingConstants.CHANNEL_POWER, OnOffType.from(power));
         updateState(AmpliPiBindingConstants.CHANNEL_MUTE, OnOffType.from(mute));
         updateState(AmpliPiBindingConstants.CHANNEL_VOLUME, AmpliPiUtils.volumeToPercentType(vol));
         updateState(AmpliPiBindingConstants.CHANNEL_SOURCE, new DecimalType(sourceId));
index df5f8400c959e5d2d632230659674b62f47683aa..c6fc68fd657099868c745e9b41c786adfc931a45 100644 (file)
                <description>A zone of the AmpliPi system</description>
 
                <channels>
+                       <channel typeId="system.power" id="power"/>
                        <channel typeId="system.volume" id="volume"/>
                        <channel typeId="system.mute" id="mute"/>
                        <channel typeId="source" id="source"/>
                </channels>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <config-description>
                        <parameter name="id" type="integer" required="true">
                                <label>Zone ID</label>
                <description>A group of the AmpliPi system</description>
 
                <channels>
+                       <channel typeId="system.power" id="power"/>
                        <channel typeId="system.volume" id="volume"/>
                        <channel typeId="system.mute" id="mute"/>
                        <channel typeId="source" id="source"/>
                </channels>
 
+               <properties>
+                       <property name="thingTypeVersion">1</property>
+               </properties>
+
                <config-description>
                        <parameter name="id" type="integer" required="true">
                                <label>Group ID</label>
diff --git a/bundles/org.openhab.binding.amplipi/src/main/resources/OH-INF/update/binding.xml b/bundles/org.openhab.binding.amplipi/src/main/resources/OH-INF/update/binding.xml
new file mode 100644 (file)
index 0000000..8b8d48b
--- /dev/null
@@ -0,0 +1,19 @@
+<?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="amplipi:zone">
+               <instruction-set targetVersion="1">
+                       <add-channel id="power">
+                               <type>system:power</type>
+                       </add-channel>
+               </instruction-set>
+       </thing-type>
+       <thing-type uid="amplipi:group">
+               <instruction-set targetVersion="1">
+                       <add-channel id="power">
+                               <type>system:power</type>
+                       </add-channel>
+               </instruction-set>
+       </thing-type>
+</update:update-descriptions>