Skip to content

Commit

Permalink
[emotiva] Code review round 3:
Browse files Browse the repository at this point in the history
* Discovery method
* Model and revisions as properties
* Rename keep-alive to last-seen

Signed-off-by: Espen Fossen <espenaf@junta.no>
  • Loading branch information
espenaf committed May 24, 2024
1 parent 97179d6 commit 4187a31
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 72 deletions.
20 changes: 11 additions & 9 deletions bundles/org.openhab.binding.emotiva/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ The binding automatically discovers devices on your network.
The Emotiva Processor thing requires the `ipAddress` it can connect to.
There are more parameters which all have defaults set.

| Parameter | Values | Default |
|-----------------|---------------------------------------------------------------|---------|
| ipAddress | IP address of the processor | - |
| controlPort | port number, e.g. 7002 | 7002 |
| notifyPort | port number, e.g. 7003 | 7003 |
| setupPortTCP | port number, e.g. 7100 | 7100 |
| menuNotifyPort | port number, e.g. 7005 | 7005 |
| protocolVersion | Emotiva Network Protocol version, e.g. 3.0 | 2.0 |
| keepAlive | Time between notification update from device, in milliseconds | 7500 |
| Parameter | Values | Default |
|-----------------------|---------------------------------------------------------------|---------|
| ipAddress | IP address of the processor | - |
| controlPort | port number, e.g. 7002 | 7002 |
| notifyPort | port number, e.g. 7003 | 7003 |
| infoPort | port number, e.g. 7004 | 7004 |
| setupPortTCP | port number, e.g. 7100 | 7100 |
| menuNotifyPort | port number, e.g. 7005 | 7005 |
| protocolVersion | Emotiva Network Protocol version, e.g. 3.0 | 2.0 |
| keepAlive | Time between notification update from device, in milliseconds | 7500 |
| retryConnectInMinutes | Time between connection retry, in minutes | 2 |


## Channels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public class EmotivaBindingConstants {
public static final String CHANNEL_BASS = "general#bass";
public static final String CHANNEL_WIDTH = "general#width";
public static final String CHANNEL_HEIGHT = "general#height";
public static final String CHANNEL_KEEP_ALIVE = "general#keep-alive";
public static final String CHANNEL_LAST_SEEN = "general#last-seen";
public static final String CHANNEL_BAR = "general#bar";
public static final String CHANNEL_MENU_DISPLAY_PREFIX = "general#menu-display";
public static final String CHANNEL_MENU_DISPLAY_HIGHLIGHT = "general#menu-display-highlight";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class EmotivaConfiguration {
public int infoPort = 7004;
public int setupPortTCP = 7100;
public int menuNotifyPort = 7005;
public String model = "";
public String revision = "";
public String dataRevision = "";
public String protocolVersion = DEFAULT_EMOTIVA_PROTOCOL_VERSION;
public int keepAlive = DEFAULT_KEEP_ALIVE_IN_MILLISECONDS;
public int retryConnectInMinutes = DEFAULT_RETRY_INTERVAL_MINUTES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,7 @@
package org.openhab.binding.emotiva.internal;

import static java.lang.String.format;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_BAR;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_INPUT1;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_KEEP_ALIVE;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_MAIN_VOLUME;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_MAIN_VOLUME_DB;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_MENU;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_MENU_DISPLAY_HIGHLIGHT;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_MENU_DISPLAY_PREFIX;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_MODE;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_MUTE;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_TUNER_CHANNEL;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_ZONE2_MUTE;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_ZONE2_VOLUME;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.CHANNEL_ZONE2_VOLUME_DB;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.DEFAULT_CONNECTION_RETRIES;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.DEFAULT_KEEP_ALIVE_CONSIDERED_LOST_IN_MILLISECONDS;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.DEFAULT_KEEP_ALIVE_IN_MILLISECONDS;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.DEFAULT_RETRY_INTERVAL_MINUTES;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.MAP_SOURCES_MAIN_ZONE;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.MAP_SOURCES_ZONE_2;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.MENU_PANEL_CHECKBOX_ON;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.MENU_PANEL_HIGHLIGHTED;
import static org.openhab.binding.emotiva.internal.EmotivaBindingConstants.*;
import static org.openhab.binding.emotiva.internal.EmotivaCommandHelper.channelToControlRequest;
import static org.openhab.binding.emotiva.internal.EmotivaCommandHelper.getMenuPanelColumnLabel;
import static org.openhab.binding.emotiva.internal.EmotivaCommandHelper.getMenuPanelRowLabel;
Expand Down Expand Up @@ -289,7 +268,7 @@ private void startPollingKeepAlive() {
private void checkKeepAliveTimestamp() {

if (ThingStatus.ONLINE.equals(getThing().getStatusInfo().getStatus())) {
State state = stateMap.get(CHANNEL_KEEP_ALIVE);
State state = stateMap.get(CHANNEL_LAST_SEEN);
if (state instanceof Number value) {
Instant lastKeepAliveMessageTimestamp = Instant.ofEpochSecond(value.longValue());
Instant deviceGoneGracePeriod = Instant.now().minus(config.keepAlive, ChronoUnit.MILLIS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public enum EmotivaSubscriptionTags {
menu_update("menu-update", STRING, CHANNEL_MENU_DISPLAY_PREFIX),

/* Protocol V3 notify tags */
keepAlive("keepAlive", NUMBER_TIME, CHANNEL_KEEP_ALIVE),
keepAlive("keepAlive", NUMBER_TIME, CHANNEL_LAST_SEEN),
goodBye("goodBye", GOODBYE, ""),
bar_update("bar-update", STRING, CHANNEL_BAR),
width("width", DIMENSIONLESS_DECIBEL, CHANNEL_WIDTH),
Expand Down Expand Up @@ -163,7 +163,7 @@ public static EmotivaSubscriptionTags[] speakerChannels() {
}

public static List<EmotivaSubscriptionTags> noSubscriptionToChannel() {
return List.of(keepAlive, goodBye);
return List.of(goodBye);
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@
<description>This is the binding for devices from the Emotiva Audio Corporation.</description>
<connection>local</connection>

<discovery-methods>
<discovery-method>
<service-type>ip</service-type>
<discovery-parameters>
<discovery-parameter>
<name>type</name>
<value>ipBroadcast</value>
</discovery-parameter>
<discovery-parameter>
<name>destPort</name>
<value>7001</value>
</discovery-parameter>
<discovery-parameter>
<name>timeoutMs</name>
<value>1000</value>
</discovery-parameter>
</discovery-parameters>
</discovery-method>
</discovery-methods>

</addon:addon>
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,12 @@
<default>7100</default>
<advanced>true</advanced>
</parameter>
<parameter name="model" type="text" required="false" readOnly="true">
<context>model</context>
<label>Model Name</label>
<description>Device model name</description>
</parameter>
<parameter name="revision" type="text" required="false" readOnly="true">
<context>revision</context>
<label>Device Revision</label>
<description>Revision for given Emotiva device model</description>
<advanced>true</advanced>
</parameter>
<parameter name="dataRevision" type="text" required="false" readOnly="true">
<context>data-revision</context>
<label>Data Revision</label>
<description>Data revision for given Emotiva device model</description>
<advanced>true</advanced>
</parameter>
<parameter name="protocolVersion" type="text" required="false">
<context>protocol-revision</context>
<label>Protocol Version</label>
<description>Protocol version, only change if you know what your doing</description>
<advanced>true</advanced>
</parameter>
<parameter name="keepAlive" type="integer" required="false" unit="ms">
<context>keep-alive</context>
<label>Keep Alive Notification</label>
<description>The interval, in milliseconds, at which the Emotiva Device will send a "keepAlive"
notification
</description>
<advanced>true</advanced>
</parameter>
<parameter name="retryConnectInMinutes" type="integer" required="false" unit="s">
<label>Reconnect Interval</label>
<description>The time to wait between reconnection attempts (in minutes)</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ thing-type.config.emotiva.config.setupPortTCP.label = Setup TCP Port
thing-type.config.emotiva.config.setupPortTCP.description = TCP port for remote setup
thing-type.config.emotiva.config.menuNotifyPort.label = Menu Notify Port
thing-type.config.emotiva.config.menuNotifyPort.description = UDP port to receive menu notifications from the device
thing-type.config.emotiva.config.model.label = Device Model
thing-type.config.emotiva.config.model.description = Model name of the Emotiva device
thing-type.config.emotiva.config.revision.label = Model Revision
thing-type.config.emotiva.config.revision.description = Revision of the device model
thing-type.config.emotiva.config.dataRevision.label = Data Revision
thing-type.config.emotiva.config.dataRevision.description = Data revision for the device model
thing-type.config.emotiva.config.protocolVersion.label = Emotiva Protocol Version
thing-type.config.emotiva.config.protocolVersion.description = Emotiva Network Remote Control protocol version
thing-type.config.emotiva.config.keepAlive.label = Keep Alive Notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
</channel-group>
</channel-groups>

<properties>
<property name="model">Unknown Model</property>
<property name="revision">Unknown Model Revision</property>
<property name="dataRevision">Unknown Data Revision</property>
</properties>

<representation-property>ipAddress</representation-property>

<config-description-ref uri="thing-type:processor:config"/>
Expand Down Expand Up @@ -101,7 +107,9 @@
<channel id="width" typeId="volume-speaker-db"/>
<channel id="height" typeId="volume-speaker-db"/>
<channel id="bar" typeId="bar"/>
<channel id="keep-alive" typeId="keep-alive"/>

<channel id="last-seen" typeId="last-seen"/>

</channels>
</channel-group-type>

Expand Down Expand Up @@ -466,9 +474,9 @@
<state readOnly="true"/>
</channel-type>

<channel-type id="keep-alive">
<channel-type id="last-seen">
<item-type>Number:Time</item-type>
<label>Keep Alive Timestamp</label>
<label>Last Seen</label>
<description>Timestamp of last received keepAlive message.</description>
</channel-type>

Expand Down

0 comments on commit 4187a31

Please sign in to comment.