Skip to content

Commit

Permalink
[androidtv] Fixes Bugs and Prepares for PhilipsTV (openhab#16191)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Rosenblum <[email protected]>
  • Loading branch information
morph166955 authored Jan 12, 2024
1 parent 444d824 commit 8993d86
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 77 deletions.
2 changes: 2 additions & 0 deletions bundles/org.openhab.binding.androidtv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ There are three required fields to connect successfully to a ShieldTV.
| Name | Type | Description | Default | Required | Advanced |
|------------------|---------|---------------------------------------|---------|----------|----------|
| ipAddress | text | IP address of the device | N/A | yes | no |
| googletvPort | text | TCP Port for GoogleTV | 6466 | no | no |
| shieldtvPort | text | TCP Port for ShieldTV | 8987 | no | no |
| keystore | text | Location of the Java Keystore | N/A | no | no |
| keystorePassword | text | Password of the Java Keystore | N/A | no | no |
| gtvEnabled | boolean | Enable/Disable the GoogleTV protocol | true | no | no |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public class AndroidTVBindingConstants {
public static final String CHANNEL_PLAYER = "player";

// List of all config properties
public static final String PROPERTY_IP_ADDRESS = "ipAddress";
public static final String PROPERTY_GTV_ENABLED = "gtvEnabled";
public static final String PARAMETER_IP_ADDRESS = "ipAddress";
public static final String PARAMETER_GOOGLETV_PORT = "googletvPort";
public static final String PARAMETER_SHIELDTV_PORT = "shieldtvPort";
public static final String PARAMETER_GTV_ENABLED = "gtvEnabled";

// List of all static String literals
public static final String PIN_REQUEST = "REQUEST";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,18 @@ public void checkThingStatus() {
failed = true;
}
statusMessage = "GoogleTV: " + googletvConnectionManager.getStatusMessage();

if (!THING_TYPE_GOOGLETV.equals(thingTypeUID)) {
statusMessage = statusMessage + " | ";
}
}

if (THING_TYPE_SHIELDTV.equals(thingTypeUID)) {
if (shieldtvConnectionManager != null) {
if (!shieldtvConnectionManager.getLoggedIn()) {
failed = true;
}
statusMessage = statusMessage + " | ShieldTV: " + shieldtvConnectionManager.getStatusMessage();
statusMessage = statusMessage + "ShieldTV: " + shieldtvConnectionManager.getStatusMessage();
}
}

Expand All @@ -159,13 +163,13 @@ public void initialize() {
String ipAddress = googletvConfig.ipAddress;
boolean gtvEnabled = googletvConfig.gtvEnabled;

if (ipAddress.isBlank()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"@text/offline.googletv-address-not-specified");
return;
}

if (THING_TYPE_GOOGLETV.equals(thingTypeUID) || gtvEnabled) {
if (ipAddress.isBlank()) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"@text/offline.googletv-address-not-specified");
return;
}

googletvConnectionManager = new GoogleTVConnectionManager(this, googletvConfig);
}

Expand All @@ -186,6 +190,13 @@ public void initialize() {
TimeUnit.MILLISECONDS);
}

public void sendCommandToProtocol(ChannelUID channelUID, Command command) {
ShieldTVConnectionManager shieldtvConnectionManager = this.shieldtvConnectionManager;
if (THING_TYPE_SHIELDTV.equals(thingTypeUID) && (shieldtvConnectionManager != null)) {
shieldtvConnectionManager.handleCommand(channelUID, command);
}
}

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.trace("{} - Command received at handler: {} {}", this.thingID, channelUID.getId(), command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public String getServiceType() {
if (uid != null) {
final String id = uid.getId();
final String label = service.getName() + " (" + id + ")";
final Map<String, Object> properties = Map.of(PROPERTY_IP_ADDRESS, ipAddress);
final Map<String, Object> properties = Map.of(PARAMETER_IP_ADDRESS, ipAddress);

return DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label).build();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public String getServiceType() {
if (uid != null) {
final String id = uid.getId();
final String label = service.getName() + " (" + id + ")";
final Map<String, Object> properties = Map.of(PROPERTY_IP_ADDRESS, ipAddress);
final Map<String, Object> properties = Map.of(PARAMETER_IP_ADDRESS, ipAddress);

return DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label).build();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class GoogleTVConfiguration {

public String ipAddress = "";
public int port = 6466;
public int googletvPort = 6466;
public int reconnect;
public int heartbeat;
public String keystoreFileName = "";
Expand Down
Loading

0 comments on commit 8993d86

Please sign in to comment.