Skip to content

Commit

Permalink
add channels for sounds to bridge
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Lauterbach <thomas@pop-os.amfthome.org>
  • Loading branch information
Thomas Lauterbach committed Jan 5, 2025
1 parent 1b81311 commit e28769e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class AwtrixLightBindingConstants {
public static final String TOPIC_NOTIFY = "/notify";
public static final String TOPIC_POWER = "/power";
public static final String TOPIC_REBOOT = "/reboot";
public static final String TOPIC_RTTTL = "/rtttl";
public static final String TOPIC_SCREEN = "/screen";
public static final String TOPIC_SEND_SCREEN = "/sendscreen";
public static final String TOPIC_SETTINGS = "/settings";
Expand Down Expand Up @@ -106,8 +107,6 @@ public class AwtrixLightBindingConstants {
public static final String FIELD_BRIDGE_SET_BLOCK_KEYS = "BLOCKN";
public static final String FIELD_BRIDGE_SET_BRIGHTNESS = "BRI";
public static final String FIELD_BRIDGE_SET_DISPLAY = "MATP";

// TODO: Validate that it really mutes
public static final String FIELD_BRIDGE_SET_MUTE = "SOUND";
public static final String FIELD_BRIDGE_SET_SCROLL_SPEED = "SSPEED";
public static final String FIELD_BRIDGE_SET_TEXT_COLOR = "TCOL";
Expand Down Expand Up @@ -136,7 +135,9 @@ public class AwtrixLightBindingConstants {
public static final String CHANNEL_LOW_BATTERY = "low-battery";
public static final String CHANNEL_LUX = "lux";
public static final String CHANNEL_RSSI = "rssi";
public static final String CHANNEL_RTTTL = "rtttl";
public static final String CHANNEL_SCREEN = "screen";
public static final String CHANNEL_SOUND = "sound";
public static final String CHANNEL_TEMPERATURE = "temperature";

// App Channels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ public static void playSound(@Nullable ThingActions actions, @Nullable String me
}
}

@RuleAction(label = "Play RTTTL", description = "Plays the melody provided in RTTTL format")
public void playRtttl(String rtttl) {
AwtrixLightBridgeHandler localHandler = this.handler;
if (localHandler != null) {
localHandler.playRtttl(rtttl);
}
}

public static void playRtttl(@Nullable ThingActions actions, @Nullable String rtttl) {
if (actions instanceof AwtrixActions) {
if (rtttl != null) {
((AwtrixActions) actions).playRtttl(rtttl);
}
} else {
throw new IllegalArgumentException("Instance is not an AwtrixActions class.");
}
}

@RuleAction(label = "Show Notification", description = "Shows a default notification with an icon")
public void showNotification(String message, String icon) {
AwtrixLightBridgeHandler localHandler = this.handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,7 @@

package org.openhab.binding.mqtt.awtrixlight.internal.handler;

import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_APP;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_AUTO_BRIGHTNESS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_BATTERY;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_BRIGHTNESS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_BUTLEFT;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_BUTRIGHT;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_BUTSELECT;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_DISPLAY;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_HUMIDITY;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_INDICATOR1;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_INDICATOR2;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_INDICATOR3;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_LOW_BATTERY;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_LUX;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_RSSI;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_SCREEN;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.CHANNEL_TEMPERATURE;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.DEFAULT_APPS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_APP;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_BATTERY;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_BATTERY_RAW;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_BRIGHTNESS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_FIRMWARE;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_HUMIDITY;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_INDICATOR1;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_INDICATOR2;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_INDICATOR3;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_LDR_RAW;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_LUX;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_MATRIX;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_MESSAGES;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_RAM;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_SET_AUTO_BRIGHTNESS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_SET_AUTO_TRANSITION;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_SET_BLOCK_KEYS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_SET_BRIGHTNESS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_TEMPERATURE;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_TYPE;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_UID;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_UPTIME;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.FIELD_BRIDGE_WIFI_SIGNAL;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.PROP_FIRMWARE;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.PROP_UNIQUEID;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.PROP_VENDOR;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.THING_TYPE_BRIDGE;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_BUTLEFT;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_BUTRIGHT;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_BUTSELECT;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_INDICATOR1;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_INDICATOR2;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_INDICATOR3;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_NOTIFY;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_POWER;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_REBOOT;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_SCREEN;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_SEND_SCREEN;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_SETTINGS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_SLEEP;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_SOUND;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_STATS;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_STATS_CURRENT_APP;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.TOPIC_UPGRADE;
import static org.openhab.binding.mqtt.awtrixlight.internal.AwtrixLightBindingConstants.*;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -214,6 +153,16 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
}
break;
case CHANNEL_SOUND:
if (command instanceof StringType) {
playSound(command.toString());
}
break;
case CHANNEL_RTTTL:
if (command instanceof StringType) {
playRtttl(command.toString());
}
break;
}
}

Expand Down Expand Up @@ -368,6 +317,10 @@ public void playSound(String melodyName) {
this.sendMQTT(this.basetopic + TOPIC_SOUND, "{\"sound\":\"" + melodyName + "\"}", false);
}

public void playRtttl(String rtttl) {
this.sendMQTT(this.basetopic + TOPIC_RTTTL, rtttl, false);
}

public void upgrade() {
this.sendMQTT(this.basetopic + TOPIC_UPGRADE, "", false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
<channel id="indicator1" typeId="indicator"/>
<channel id="indicator2" typeId="indicator"/>
<channel id="indicator3" typeId="indicator"/>
<channel id="sound" typeId="sound"/>
<channel id="rtttl" typeId="rtttl"/>
</channels>
<properties>
<property name="vendor"></property>
<property name="firmware"></property>
<property name="uniqueId"></property>
<property name="thingTypeVersion">1</property>
</properties>
<representation-property>uniqueId</representation-property>
<config-description-ref uri="thing-type:mqtt:awtrixclock"/>
Expand Down Expand Up @@ -547,4 +550,24 @@
<state pattern="%.0f %unit%"></state>
</channel-type>

<channel-type id="sound">
<item-type>String</item-type>
<label>Play melody from MELODIES folder</label>
<description>Name of the melody file in the clocks MELODIES folder</description>
<category>text</category>
<tags>
<tag>Point</tag>
</tags>
</channel-type>

<channel-type id="rtttl">
<item-type>String</item-type>
<label>Play RTTTL</label>
<description>Ring Tone Text Transfer Language (RTTTL) compliant sound string</description>
<category>text</category>
<tags>
<tag>Point</tag>
</tags>
</channel-type>

</thing:thing-descriptions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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="mqtt:awtrixclock">
<instruction-set targetVersion="1">
<add-channel id="sound">
<type>mqtt:sound</type>
</add-channel>
<add-channel id="rtttl">
<type>mqtt:rtttl</type>
</add-channel>
</instruction-set>
</thing-type>

</update:update-descriptions>

0 comments on commit e28769e

Please sign in to comment.