Skip to content

Commit

Permalink
[Chromecast] Added support for Audio groups fixes openhab#1853, fixes o…
Browse files Browse the repository at this point in the history
…penhab#1766

Creates additional THING_TYPE for Audio Groups. If device added by
discovery uses discovered port number, else provides default 8009.

Signed-off-by: Sean McGuire <[email protected]> (github: mcguiresean)
  • Loading branch information
Sean McGuire committed Feb 16, 2017
2 parents 4596c4a + 1b1dcad commit 14335c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<required>true</required>
</parameter>
<parameter name="port" type="integer">
<context>network-port</context>
<label>Network Port</label>
<description>Network port of the Chromecast device.</description>
<required>true</required>
<advanced>true</advanced>
<default>8009</default>
</parameter>
</config-description>
</thing-type>
Expand All @@ -52,10 +52,10 @@
<required>true</required>
</parameter>
<parameter name="port" type="integer">
<context>network-port</context>
<label>Network Port</label>
<description>Network port of the Chromecast device.</description>
<required>true</required>
<advanced>true</advanced>
<default>8009</default>
</parameter>
</config-description>
</thing-type>
Expand All @@ -79,10 +79,10 @@
<required>true</required>
</parameter>
<parameter name="port" type="integer">
<context>network-port</context>
<label>Network Port</label>
<description>Network port of the Chromecast device.</description>
<required>true</required>
<advanced>true</advanced>
<default>8009</default>
</parameter>
</config-description>
</thing-type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.openhab.binding.chromecast.handler;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
Expand Down Expand Up @@ -148,21 +149,26 @@ public void initialize() {
"Cannot connect to Chromecast. IP address is invalid.");
return;
}
final Object portnumber = getConfig().get(ChromecastBindingConstants.PORT);
if (!(portnumber instanceof Integer)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
"Cannot connect to Chromecast. port is invalid.");
return;
}

final String host = (String) ipAddress;
if (StringUtils.isBlank(host)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.CONFIGURATION_ERROR,
"Cannot connect to Chromecast. IP address is not set.");
return;
}
final int port = (Integer) portnumber;

if (chromecast != null && !chromecast.getAddress().equals(host) && !(chromecast.getPort() == port)) {
final Object portnumber = getConfig().get(ChromecastBindingConstants.PORT);
logger.debug("Variable Type is {}", portnumber.getClass().getTypeName());
final int port;
if (portnumber instanceof BigDecimal) {
port = ((BigDecimal) portnumber).intValue();
} else if (portnumber instanceof Integer) {
port = (Integer) portnumber;
} else {
port = 8009;
}

if (chromecast != null && (!chromecast.getAddress().equals(host) || (chromecast.getPort() != port))) {
destroyChromecast();
}
if (chromecast == null) {
Expand Down

0 comments on commit 14335c0

Please sign in to comment.