Skip to content

Commit

Permalink
[amplipi] Add new power channel to zones and groups (#16171)
Browse files Browse the repository at this point in the history
* [amplipi] Add new power channel to zones and groups

Signed-off-by: Kai Kreuzer <[email protected]>
  • Loading branch information
kaikreuzer authored Jan 2, 2024
1 parent 8a0361f commit f079d1d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bundles/org.openhab.binding.amplipi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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" }
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
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);
Expand Down Expand Up @@ -159,10 +164,12 @@ public void receive(Status status) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
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);
Expand Down Expand Up @@ -159,10 +164,12 @@ public void receive(Status status) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,16 @@
<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>
Expand All @@ -79,11 +84,16 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit f079d1d

Please sign in to comment.