mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Compare commits
5 Commits
c8c5d19bb6
...
1955677cdb
Author | SHA1 | Date | |
---|---|---|---|
|
1955677cdb | ||
|
f6efa87fb2 | ||
|
98ff656400 | ||
|
f6c6a3cf82 | ||
|
6b42d75378 |
@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) 2010-2025 Contributors to the openHAB project
|
* Copyright (c) 2010-2025 Contributors to the openHAB project
|
||||||
*
|
*
|
||||||
* See the NOTICE file(s) distributed with this work for additional
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/**
|
/*
|
||||||
* Copyright (c) 2010-2025 Contributors to the openHAB project
|
* Copyright (c) 2010-2025 Contributors to the openHAB project
|
||||||
*
|
*
|
||||||
* See the NOTICE file(s) distributed with this work for additional
|
* See the NOTICE file(s) distributed with this work for additional
|
||||||
|
@ -19,6 +19,7 @@ import java.time.Duration;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -37,6 +38,7 @@ import org.openhab.core.config.core.Configuration;
|
|||||||
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
import org.openhab.core.config.discovery.AbstractDiscoveryService;
|
||||||
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
|
||||||
import org.openhab.core.config.discovery.DiscoveryService;
|
import org.openhab.core.config.discovery.DiscoveryService;
|
||||||
|
import org.openhab.core.net.CidrAddress;
|
||||||
import org.openhab.core.thing.ThingUID;
|
import org.openhab.core.thing.ThingUID;
|
||||||
import org.osgi.service.component.annotations.Activate;
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
@ -133,37 +135,43 @@ public class NetworkDiscoveryService extends AbstractDiscoveryService implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
removeOlderResults(getTimestampOfLastScan(), null);
|
removeOlderResults(getTimestampOfLastScan(), null);
|
||||||
logger.trace("Starting Network Device Discovery");
|
logger.debug("Starting Network Device Discovery");
|
||||||
|
Map<String, Set<CidrAddress>> discoveryList = networkUtils.getNetworkIPsPerInterface();
|
||||||
|
|
||||||
final Set<String> networkIPs = networkUtils.getNetworkIPs(MAXIMUM_IPS_PER_INTERFACE);
|
for (String networkInterface : discoveryList.keySet()) {
|
||||||
scannedIPcount.set(0);
|
final Set<String> networkIPs = networkUtils.getNetworkIPs(
|
||||||
|
Objects.requireNonNull(discoveryList.get(networkInterface)), MAXIMUM_IPS_PER_INTERFACE);
|
||||||
|
logger.debug("Scanning {} IPs on interface {} ", networkIPs.size(), networkInterface);
|
||||||
|
scannedIPcount.set(0);
|
||||||
|
for (String ip : networkIPs) {
|
||||||
|
final PresenceDetection pd = new PresenceDetection(this, scheduler, Duration.ofSeconds(2));
|
||||||
|
pd.setHostname(ip);
|
||||||
|
pd.setNetworkInterfaceNames(Set.of(networkInterface));
|
||||||
|
pd.setIOSDevice(true);
|
||||||
|
pd.setUseDhcpSniffing(false);
|
||||||
|
pd.setTimeout(PING_TIMEOUT);
|
||||||
|
// Ping devices
|
||||||
|
pd.setUseIcmpPing(true);
|
||||||
|
pd.setUseArpPing(true, configuration.arpPingToolPath, configuration.arpPingUtilMethod);
|
||||||
|
// TCP devices
|
||||||
|
pd.setServicePorts(tcpServicePorts);
|
||||||
|
|
||||||
for (String ip : networkIPs) {
|
service.execute(() -> {
|
||||||
final PresenceDetection pd = new PresenceDetection(this, scheduler, Duration.ofSeconds(2));
|
Thread.currentThread().setName("Discovery thread " + ip);
|
||||||
pd.setHostname(ip);
|
try {
|
||||||
pd.setIOSDevice(true);
|
pd.getValue();
|
||||||
pd.setUseDhcpSniffing(false);
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
pd.setTimeout(PING_TIMEOUT);
|
stopScan();
|
||||||
// Ping devices
|
}
|
||||||
pd.setUseIcmpPing(true);
|
int count = scannedIPcount.incrementAndGet();
|
||||||
pd.setUseArpPing(true, configuration.arpPingToolPath, configuration.arpPingUtilMethod);
|
if (count == networkIPs.size()) {
|
||||||
// TCP devices
|
logger.trace("Scan of {} IPs on interface {} successful", scannedIPcount, networkInterface);
|
||||||
pd.setServicePorts(tcpServicePorts);
|
stopScan();
|
||||||
|
}
|
||||||
service.execute(() -> {
|
});
|
||||||
Thread.currentThread().setName("Discovery thread " + ip);
|
}
|
||||||
try {
|
|
||||||
pd.getValue();
|
|
||||||
} catch (ExecutionException | InterruptedException e) {
|
|
||||||
stopScan();
|
|
||||||
}
|
|
||||||
int count = scannedIPcount.incrementAndGet();
|
|
||||||
if (count == networkIPs.size()) {
|
|
||||||
logger.trace("Scan of {} IPs successful", scannedIPcount);
|
|
||||||
stopScan();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
logger.debug("Finished Network Device Discovery");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,9 +32,11 @@ import java.time.Duration;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -139,7 +141,7 @@ public class NetworkUtils {
|
|||||||
try {
|
try {
|
||||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||||
NetworkInterface networkInterface = en.nextElement();
|
NetworkInterface networkInterface = en.nextElement();
|
||||||
if (!networkInterface.isLoopback()) {
|
if (networkInterface.isUp() && !networkInterface.isLoopback()) {
|
||||||
result.add(networkInterface.getName());
|
result.add(networkInterface.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,6 +162,30 @@ public class NetworkUtils {
|
|||||||
return getNetworkIPs(getInterfaceIPs(), maximumPerInterface);
|
return getNetworkIPs(getInterfaceIPs(), maximumPerInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a map of network interface names to their associated IP addresses.
|
||||||
|
*
|
||||||
|
* @return A map where the key is the name of the network interface and the value is a set of CidrAddress objects
|
||||||
|
* representing the IP addresses and network prefix lengths for that interface.
|
||||||
|
*/
|
||||||
|
public Map<String, Set<CidrAddress>> getNetworkIPsPerInterface() {
|
||||||
|
Map<String, Set<CidrAddress>> outputMap = new HashMap<>();
|
||||||
|
try {
|
||||||
|
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||||
|
NetworkInterface networkInterface = en.nextElement();
|
||||||
|
if (networkInterface.isUp() && !networkInterface.isLoopback()) {
|
||||||
|
outputMap.put(networkInterface.getName(),
|
||||||
|
networkInterface.getInterfaceAddresses().stream()
|
||||||
|
.map(m -> new CidrAddress(m.getAddress(), m.getNetworkPrefixLength()))
|
||||||
|
.collect(Collectors.toSet()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SocketException e) {
|
||||||
|
logger.trace("Could not get network interfaces", e);
|
||||||
|
}
|
||||||
|
return outputMap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes the interfaceIPs and fetches every IP which can be assigned on their network
|
* Takes the interfaceIPs and fetches every IP which can be assigned on their network
|
||||||
*
|
*
|
||||||
@ -167,7 +193,7 @@ public class NetworkUtils {
|
|||||||
* @param maximumPerInterface The maximum of IP addresses per interface or 0 to get all.
|
* @param maximumPerInterface The maximum of IP addresses per interface or 0 to get all.
|
||||||
* @return Every single IP which can be assigned on the Networks the computer is connected to
|
* @return Every single IP which can be assigned on the Networks the computer is connected to
|
||||||
*/
|
*/
|
||||||
private Set<String> getNetworkIPs(Set<CidrAddress> interfaceIPs, int maximumPerInterface) {
|
public Set<String> getNetworkIPs(Set<CidrAddress> interfaceIPs, int maximumPerInterface) {
|
||||||
Set<String> networkIPs = new LinkedHashSet<>();
|
Set<String> networkIPs = new LinkedHashSet<>();
|
||||||
|
|
||||||
short minCidrPrefixLength = 8; // historic Class A network, addresses = 16777214
|
short minCidrPrefixLength = 8; // historic Class A network, addresses = 16777214
|
||||||
|
@ -46,6 +46,8 @@ The following channels are available:
|
|||||||
| playMode | String | The current playback mode ie: stop, play, pause (ReadOnly). |
|
| playMode | String | The current playback mode ie: stop, play, pause (ReadOnly). |
|
||||||
| timeElapsed | Number:Time | The total number of seconds of playback time elapsed for the current playing title (ReadOnly). |
|
| timeElapsed | Number:Time | The total number of seconds of playback time elapsed for the current playing title (ReadOnly). |
|
||||||
| timeTotal | Number:Time | The total length of the current playing title in seconds (ReadOnly). This data is not provided by all streaming apps. |
|
| timeTotal | Number:Time | The total length of the current playing title in seconds (ReadOnly). This data is not provided by all streaming apps. |
|
||||||
|
| endTime | DateTime | The date/time when the currently playing media will end (ReadOnly). N/A if timeTotal is not provided by the current streaming app. |
|
||||||
|
| progress | Dimmer | The current progress [0-100%] of playing media (ReadOnly). N/A if timeTotal is not provided by the current streaming app. |
|
||||||
| activeChannel | String | A dropdown containing a list of available TV channels on the Roku TV. The channel currently tuned is automatically selected. The list updates every 10 minutes. |
|
| activeChannel | String | A dropdown containing a list of available TV channels on the Roku TV. The channel currently tuned is automatically selected. The list updates every 10 minutes. |
|
||||||
| signalMode | String | The signal type of the current TV channel, ie: 1080i (ReadOnly). |
|
| signalMode | String | The signal type of the current TV channel, ie: 1080i (ReadOnly). |
|
||||||
| signalQuality | Number:Dimensionless | The signal quality of the current TV channel, 0-100% (ReadOnly). |
|
| signalQuality | Number:Dimensionless | The signal quality of the current TV channel, 0-100% (ReadOnly). |
|
||||||
@ -59,6 +61,7 @@ The following channels are available:
|
|||||||
Some Notes:
|
Some Notes:
|
||||||
|
|
||||||
- The values for `activeApp`, `activeAppName`, `playMode`, `timeElapsed`, `timeTotal`, `activeChannel`, `signalMode`, `signalQuality`, `channelName`, `programTitle`, `programDescription`, `programRating`, `power` & `powerState` refresh automatically per the configured `refresh` interval.
|
- The values for `activeApp`, `activeAppName`, `playMode`, `timeElapsed`, `timeTotal`, `activeChannel`, `signalMode`, `signalQuality`, `channelName`, `programTitle`, `programDescription`, `programRating`, `power` & `powerState` refresh automatically per the configured `refresh` interval.
|
||||||
|
- The `endTime` and `progress` channels may not be accurate for some streaming apps especially 'live' streams where the `timeTotal` value constantly increases.
|
||||||
|
|
||||||
**List of available button commands for Roku streaming devices:**
|
**List of available button commands for Roku streaming devices:**
|
||||||
|
|
||||||
@ -113,32 +116,36 @@ roku:roku_tv:mytv1 "My Roku TV" [ hostName="192.168.10.1", refresh=10 ]
|
|||||||
```java
|
```java
|
||||||
// Roku streaming media player items:
|
// Roku streaming media player items:
|
||||||
|
|
||||||
String Player_ActiveApp "Current App: [%s]" { channel="roku:roku_player:myplayer1:activeApp" }
|
String Player_ActiveApp "Current App: [%s]" { channel="roku:roku_player:myplayer1:activeApp" }
|
||||||
String Player_ActiveAppName "Current App Name: [%s]" { channel="roku:roku_player:myplayer1:activeAppName" }
|
String Player_ActiveAppName "Current App Name: [%s]" { channel="roku:roku_player:myplayer1:activeAppName" }
|
||||||
String Player_Button "Send Command to Roku" { channel="roku:roku_player:myplayer1:button" }
|
String Player_Button "Send Command to Roku" { channel="roku:roku_player:myplayer1:button" }
|
||||||
Player Player_Control "Control" { channel="roku:roku_player:myplayer1:control" }
|
Player Player_Control "Control" { channel="roku:roku_player:myplayer1:control" }
|
||||||
String Player_PlayMode "Status: [%s]" { channel="roku:roku_player:myplayer1:playMode" }
|
String Player_PlayMode "Status: [%s]" { channel="roku:roku_player:myplayer1:playMode" }
|
||||||
Number:Time Player_TimeElapsed "Elapsed Time: [%d %unit%]" { channel="roku:roku_player:myplayer1:timeElapsed" }
|
Number:Time Player_TimeElapsed "Elapsed Time: [%d %unit%]" { channel="roku:roku_player:myplayer1:timeElapsed" }
|
||||||
Number:Time Player_TimeTotal "Total Time: [%d %unit%]" { channel="roku:roku_player:myplayer1:timeTotal" }
|
Number:Time Player_TimeTotal "Total Time: [%d %unit%]" { channel="roku:roku_player:myplayer1:timeTotal" }
|
||||||
|
DateTime Player_EndTime "End Time: [%1$tl:%1$tM %1$tp]" { channel="roku:roku_player:myplayer1:endTime" }
|
||||||
|
Dimmer Player_Progress "Progress [%.0f%%]" { channel="roku:roku_player:myplayer1:progress" }
|
||||||
|
|
||||||
// Roku TV items:
|
// Roku TV items:
|
||||||
|
|
||||||
Switch Player_Power "Power: [%s]" { channel="roku:roku_tv:mytv1:power" }
|
Switch Player_Power "Power: [%s]" { channel="roku:roku_tv:mytv1:power" }
|
||||||
String Player_PowerState "Power State: [%s] { channel="roku:roku_tv:mytv1:powerState" }
|
String Player_PowerState "Power State: [%s] { channel="roku:roku_tv:mytv1:powerState" }
|
||||||
String Player_ActiveApp "Current App: [%s]" { channel="roku:roku_tv:mytv1:activeApp" }
|
String Player_ActiveApp "Current App: [%s]" { channel="roku:roku_tv:mytv1:activeApp" }
|
||||||
String Player_ActiveAppName "Current App Name: [%s]" { channel="roku:roku_tv:mytv1:activeAppName" }
|
String Player_ActiveAppName "Current App Name: [%s]" { channel="roku:roku_tv:mytv1:activeAppName" }
|
||||||
String Player_Button "Send Command to Roku" { channel="roku:roku_tv:mytv1:button" }
|
String Player_Button "Send Command to Roku" { channel="roku:roku_tv:mytv1:button" }
|
||||||
Player Player_Control "Control" { channel="roku:roku_tv:mytv1:control" }
|
Player Player_Control "Control" { channel="roku:roku_tv:mytv1:control" }
|
||||||
String Player_PlayMode "Status: [%s]" { channel="roku:roku_tv:mytv1:playMode" }
|
String Player_PlayMode "Status: [%s]" { channel="roku:roku_tv:mytv1:playMode" }
|
||||||
Number:Time Player_TimeElapsed "Elapsed Time: [%d %unit%]" { channel="roku:roku_tv:mytv1:timeElapsed" }
|
Number:Time Player_TimeElapsed "Elapsed Time: [%d %unit%]" { channel="roku:roku_tv:mytv1:timeElapsed" }
|
||||||
Number:Time Player_TimeTotal "Total Time: [%d %unit%]" { channel="roku:roku_tv:mytv1:timeTotal" }
|
Number:Time Player_TimeTotal "Total Time: [%d %unit%]" { channel="roku:roku_tv:mytv1:timeTotal" }
|
||||||
String Player_ActiveChannel "Current Channel: [%s]" { channel="roku:roku_tv:mytv1:activeChannel" }
|
DateTime Player_EndTime "End Time: [%1$tl:%1$tM %1$tp]" { channel="roku:roku_tv:mytv1:endTime" }
|
||||||
String Player_SignalMode "Signal Mode: [%s]" { channel="roku:roku_tv:mytv1:signalMode" }
|
Dimmer Player_Progress "Progress [%.0f%%]" { channel="roku:roku_tv:mytv1:progress" }
|
||||||
Number Player_SignalQuality "Signal Quality: [%d %%]" { channel="roku:roku_tv:mytv1:signalQuality" }
|
String Player_ActiveChannel "Current Channel: [%s]" { channel="roku:roku_tv:mytv1:activeChannel" }
|
||||||
String Player_ChannelName "Channel Name: [%s]" { channel="roku:roku_tv:mytv1:channelName" }
|
String Player_SignalMode "Signal Mode: [%s]" { channel="roku:roku_tv:mytv1:signalMode" }
|
||||||
String Player_ProgramTitle "Program Title: [%s]" { channel="roku:roku_tv:mytv1:programTitle" }
|
Number Player_SignalQuality "Signal Quality: [%d %%]" { channel="roku:roku_tv:mytv1:signalQuality" }
|
||||||
String Player_ProgramDescription "Program Description: [%s]" { channel="roku:roku_tv:mytv1:programDescription" }
|
String Player_ChannelName "Channel Name: [%s]" { channel="roku:roku_tv:mytv1:channelName" }
|
||||||
String Player_ProgramRating "Program Rating: [%s]" { channel="roku:roku_tv:mytv1:programRating" }
|
String Player_ProgramTitle "Program Title: [%s]" { channel="roku:roku_tv:mytv1:programTitle" }
|
||||||
|
String Player_ProgramDescription "Program Description: [%s]" { channel="roku:roku_tv:mytv1:programDescription" }
|
||||||
|
String Player_ProgramRating "Program Rating: [%s]" { channel="roku:roku_tv:mytv1:programRating" }
|
||||||
```
|
```
|
||||||
|
|
||||||
### `roku.sitemap` Example
|
### `roku.sitemap` Example
|
||||||
@ -154,6 +161,8 @@ sitemap roku label="Roku" {
|
|||||||
Text item=Player_PlayMode
|
Text item=Player_PlayMode
|
||||||
Text item=Player_TimeElapsed icon="time"
|
Text item=Player_TimeElapsed icon="time"
|
||||||
Text item=Player_TimeTotal icon="time"
|
Text item=Player_TimeTotal icon="time"
|
||||||
|
Text item=Player_EndTime icon="time"
|
||||||
|
Slider item=Player_Progress icon="time"
|
||||||
// The following items apply to Roku TVs only
|
// The following items apply to Roku TVs only
|
||||||
Switch item=Player_Power
|
Switch item=Player_Power
|
||||||
Text item=Player_PowerState
|
Text item=Player_PowerState
|
||||||
|
@ -55,6 +55,8 @@ public class RokuBindingConstants {
|
|||||||
public static final String PLAY_MODE = "playMode";
|
public static final String PLAY_MODE = "playMode";
|
||||||
public static final String TIME_ELAPSED = "timeElapsed";
|
public static final String TIME_ELAPSED = "timeElapsed";
|
||||||
public static final String TIME_TOTAL = "timeTotal";
|
public static final String TIME_TOTAL = "timeTotal";
|
||||||
|
public static final String END_TIME = "endTime";
|
||||||
|
public static final String PROGRESS = "progress";
|
||||||
public static final String ACTIVE_CHANNEL = "activeChannel";
|
public static final String ACTIVE_CHANNEL = "activeChannel";
|
||||||
public static final String SIGNAL_MODE = "signalMode";
|
public static final String SIGNAL_MODE = "signalMode";
|
||||||
public static final String SIGNAL_QUALITY = "signalQuality";
|
public static final String SIGNAL_QUALITY = "signalQuality";
|
||||||
|
@ -14,6 +14,8 @@ package org.openhab.binding.roku.internal.handler;
|
|||||||
|
|
||||||
import static org.openhab.binding.roku.internal.RokuBindingConstants.*;
|
import static org.openhab.binding.roku.internal.RokuBindingConstants.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -34,8 +36,10 @@ import org.openhab.binding.roku.internal.dto.DeviceInfo;
|
|||||||
import org.openhab.binding.roku.internal.dto.Player;
|
import org.openhab.binding.roku.internal.dto.Player;
|
||||||
import org.openhab.binding.roku.internal.dto.TvChannel;
|
import org.openhab.binding.roku.internal.dto.TvChannel;
|
||||||
import org.openhab.binding.roku.internal.dto.TvChannels.Channel;
|
import org.openhab.binding.roku.internal.dto.TvChannels.Channel;
|
||||||
|
import org.openhab.core.library.types.DateTimeType;
|
||||||
import org.openhab.core.library.types.NextPreviousType;
|
import org.openhab.core.library.types.NextPreviousType;
|
||||||
import org.openhab.core.library.types.OnOffType;
|
import org.openhab.core.library.types.OnOffType;
|
||||||
|
import org.openhab.core.library.types.PercentType;
|
||||||
import org.openhab.core.library.types.PlayPauseType;
|
import org.openhab.core.library.types.PlayPauseType;
|
||||||
import org.openhab.core.library.types.QuantityType;
|
import org.openhab.core.library.types.QuantityType;
|
||||||
import org.openhab.core.library.types.StringType;
|
import org.openhab.core.library.types.StringType;
|
||||||
@ -195,21 +199,32 @@ public class RokuHandler extends BaseThingHandler {
|
|||||||
PLAY.equalsIgnoreCase(playerInfo.getState()) ? PlayPauseType.PLAY : PlayPauseType.PAUSE);
|
PLAY.equalsIgnoreCase(playerInfo.getState()) ? PlayPauseType.PLAY : PlayPauseType.PAUSE);
|
||||||
|
|
||||||
// Remove non-numeric from string, ie: ' ms'
|
// Remove non-numeric from string, ie: ' ms'
|
||||||
String position = playerInfo.getPosition().replaceAll(NON_DIGIT_PATTERN, EMPTY);
|
final String positionStr = playerInfo.getPosition().replaceAll(NON_DIGIT_PATTERN, EMPTY);
|
||||||
if (!EMPTY.equals(position)) {
|
int position = -1;
|
||||||
updateState(TIME_ELAPSED,
|
if (!EMPTY.equals(positionStr)) {
|
||||||
new QuantityType<>(Integer.parseInt(position) / 1000, API_SECONDS_UNIT));
|
position = Integer.parseInt(positionStr) / 1000;
|
||||||
|
updateState(TIME_ELAPSED, new QuantityType<>(position, API_SECONDS_UNIT));
|
||||||
} else {
|
} else {
|
||||||
updateState(TIME_ELAPSED, UnDefType.UNDEF);
|
updateState(TIME_ELAPSED, UnDefType.UNDEF);
|
||||||
}
|
}
|
||||||
|
|
||||||
String duration = playerInfo.getDuration().replaceAll(NON_DIGIT_PATTERN, EMPTY);
|
final String durationStr = playerInfo.getDuration().replaceAll(NON_DIGIT_PATTERN, EMPTY);
|
||||||
if (!EMPTY.equals(duration)) {
|
int duration = -1;
|
||||||
updateState(TIME_TOTAL,
|
if (!EMPTY.equals(durationStr)) {
|
||||||
new QuantityType<>(Integer.parseInt(duration) / 1000, API_SECONDS_UNIT));
|
duration = Integer.parseInt(durationStr) / 1000;
|
||||||
|
updateState(TIME_TOTAL, new QuantityType<>(duration, API_SECONDS_UNIT));
|
||||||
} else {
|
} else {
|
||||||
updateState(TIME_TOTAL, UnDefType.UNDEF);
|
updateState(TIME_TOTAL, UnDefType.UNDEF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (position >= 0 && duration > 0) {
|
||||||
|
updateState(END_TIME, new DateTimeType(Instant.now().plusSeconds(duration - position)));
|
||||||
|
updateState(PROGRESS,
|
||||||
|
new PercentType(BigDecimal.valueOf(Math.round(position / (double) duration * 100.0))));
|
||||||
|
} else {
|
||||||
|
updateState(END_TIME, UnDefType.UNDEF);
|
||||||
|
updateState(PROGRESS, UnDefType.UNDEF);
|
||||||
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.debug("Unable to parse playerInfo integer value. Exception: {}", e.getMessage());
|
logger.debug("Unable to parse playerInfo integer value. Exception: {}", e.getMessage());
|
||||||
} catch (RokuLimitedModeException e) {
|
} catch (RokuLimitedModeException e) {
|
||||||
@ -224,6 +239,8 @@ public class RokuHandler extends BaseThingHandler {
|
|||||||
updateState(PLAY_MODE, UnDefType.UNDEF);
|
updateState(PLAY_MODE, UnDefType.UNDEF);
|
||||||
updateState(TIME_ELAPSED, UnDefType.UNDEF);
|
updateState(TIME_ELAPSED, UnDefType.UNDEF);
|
||||||
updateState(TIME_TOTAL, UnDefType.UNDEF);
|
updateState(TIME_TOTAL, UnDefType.UNDEF);
|
||||||
|
updateState(END_TIME, UnDefType.UNDEF);
|
||||||
|
updateState(PROGRESS, UnDefType.UNDEF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thingTypeUID.equals(THING_TYPE_ROKU_TV) && tvActive) {
|
if (thingTypeUID.equals(THING_TYPE_ROKU_TV) && tvActive) {
|
||||||
|
@ -80,6 +80,8 @@ channel-type.roku.channelName.label = Channel Name
|
|||||||
channel-type.roku.channelName.description = The Name of the Channel Currently Selected
|
channel-type.roku.channelName.description = The Name of the Channel Currently Selected
|
||||||
channel-type.roku.control.label = Control
|
channel-type.roku.control.label = Control
|
||||||
channel-type.roku.control.description = Control playback e.g. Play/Pause/Next/Previous
|
channel-type.roku.control.description = Control playback e.g. Play/Pause/Next/Previous
|
||||||
|
channel-type.roku.endTime.label = End Time
|
||||||
|
channel-type.roku.endTime.description = The date/time when the currently playing media will end
|
||||||
channel-type.roku.playMode.label = Play Mode
|
channel-type.roku.playMode.label = Play Mode
|
||||||
channel-type.roku.playMode.description = The Current Playback Mode
|
channel-type.roku.playMode.description = The Current Playback Mode
|
||||||
channel-type.roku.powerState.label = Power State
|
channel-type.roku.powerState.label = Power State
|
||||||
@ -93,6 +95,8 @@ channel-type.roku.programRating.label = Program Rating
|
|||||||
channel-type.roku.programRating.description = The TV Parental Guideline Rating of the Current TV Program
|
channel-type.roku.programRating.description = The TV Parental Guideline Rating of the Current TV Program
|
||||||
channel-type.roku.programTitle.label = Program Title
|
channel-type.roku.programTitle.label = Program Title
|
||||||
channel-type.roku.programTitle.description = The Name of the Current TV Program
|
channel-type.roku.programTitle.description = The Name of the Current TV Program
|
||||||
|
channel-type.roku.progress.label = Media Progress
|
||||||
|
channel-type.roku.progress.description = The current progress of playing media
|
||||||
channel-type.roku.signalMode.label = Signal Mode
|
channel-type.roku.signalMode.label = Signal Mode
|
||||||
channel-type.roku.signalMode.description = The Signal Type of the Current TV Channel, ie: 1080i
|
channel-type.roku.signalMode.description = The Signal Type of the Current TV Channel, ie: 1080i
|
||||||
channel-type.roku.signalQuality.label = Signal Quality
|
channel-type.roku.signalQuality.label = Signal Quality
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
<channel id="playMode" typeId="playMode"/>
|
<channel id="playMode" typeId="playMode"/>
|
||||||
<channel id="timeElapsed" typeId="timeElapsed"/>
|
<channel id="timeElapsed" typeId="timeElapsed"/>
|
||||||
<channel id="timeTotal" typeId="timeTotal"/>
|
<channel id="timeTotal" typeId="timeTotal"/>
|
||||||
|
<channel id="endTime" typeId="endTime"/>
|
||||||
|
<channel id="progress" typeId="progress"/>
|
||||||
</channels>
|
</channels>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -28,7 +30,7 @@
|
|||||||
<property name="Serial Number">unknown</property>
|
<property name="Serial Number">unknown</property>
|
||||||
<property name="Device Id">unknown</property>
|
<property name="Device Id">unknown</property>
|
||||||
<property name="Software Version">unknown</property>
|
<property name="Software Version">unknown</property>
|
||||||
<property name="thingTypeVersion">1</property>
|
<property name="thingTypeVersion">2</property>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<representation-property>uuid</representation-property>
|
<representation-property>uuid</representation-property>
|
||||||
@ -52,6 +54,8 @@
|
|||||||
<channel id="playMode" typeId="playMode"/>
|
<channel id="playMode" typeId="playMode"/>
|
||||||
<channel id="timeElapsed" typeId="timeElapsed"/>
|
<channel id="timeElapsed" typeId="timeElapsed"/>
|
||||||
<channel id="timeTotal" typeId="timeTotal"/>
|
<channel id="timeTotal" typeId="timeTotal"/>
|
||||||
|
<channel id="endTime" typeId="endTime"/>
|
||||||
|
<channel id="progress" typeId="progress"/>
|
||||||
<channel id="activeChannel" typeId="activeChannel"/>
|
<channel id="activeChannel" typeId="activeChannel"/>
|
||||||
<channel id="signalMode" typeId="signalMode"/>
|
<channel id="signalMode" typeId="signalMode"/>
|
||||||
<channel id="signalQuality" typeId="signalQuality"/>
|
<channel id="signalQuality" typeId="signalQuality"/>
|
||||||
@ -69,7 +73,7 @@
|
|||||||
<property name="Serial Number">unknown</property>
|
<property name="Serial Number">unknown</property>
|
||||||
<property name="Device Id">unknown</property>
|
<property name="Device Id">unknown</property>
|
||||||
<property name="Software Version">unknown</property>
|
<property name="Software Version">unknown</property>
|
||||||
<property name="thingTypeVersion">1</property>
|
<property name="thingTypeVersion">2</property>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<representation-property>uuid</representation-property>
|
<representation-property>uuid</representation-property>
|
||||||
@ -185,6 +189,24 @@
|
|||||||
<state readOnly="true" pattern="%d %unit%"/>
|
<state readOnly="true" pattern="%d %unit%"/>
|
||||||
</channel-type>
|
</channel-type>
|
||||||
|
|
||||||
|
<channel-type id="endTime">
|
||||||
|
<item-type>DateTime</item-type>
|
||||||
|
<label>End Time</label>
|
||||||
|
<description>The date/time when the currently playing media will end</description>
|
||||||
|
<category>Time</category>
|
||||||
|
<tags>
|
||||||
|
<tag>Status</tag>
|
||||||
|
<tag>Timestamp</tag>
|
||||||
|
</tags>
|
||||||
|
<state readOnly="true"/>
|
||||||
|
</channel-type>
|
||||||
|
|
||||||
|
<channel-type id="progress">
|
||||||
|
<item-type>Dimmer</item-type>
|
||||||
|
<label>Media Progress</label>
|
||||||
|
<description>The current progress of playing media</description>
|
||||||
|
</channel-type>
|
||||||
|
|
||||||
<channel-type id="activeChannel">
|
<channel-type id="activeChannel">
|
||||||
<item-type>String</item-type>
|
<item-type>String</item-type>
|
||||||
<label>Active Channel</label>
|
<label>Active Channel</label>
|
||||||
|
@ -12,6 +12,15 @@
|
|||||||
<type>roku:control</type>
|
<type>roku:control</type>
|
||||||
</add-channel>
|
</add-channel>
|
||||||
</instruction-set>
|
</instruction-set>
|
||||||
|
|
||||||
|
<instruction-set targetVersion="2">
|
||||||
|
<add-channel id="endTime">
|
||||||
|
<type>roku:endTime</type>
|
||||||
|
</add-channel>
|
||||||
|
<add-channel id="progress">
|
||||||
|
<type>roku:progress</type>
|
||||||
|
</add-channel>
|
||||||
|
</instruction-set>
|
||||||
</thing-type>
|
</thing-type>
|
||||||
|
|
||||||
<thing-type uid="roku:roku_tv">
|
<thing-type uid="roku:roku_tv">
|
||||||
@ -29,6 +38,15 @@
|
|||||||
<type>roku:control</type>
|
<type>roku:control</type>
|
||||||
</add-channel>
|
</add-channel>
|
||||||
</instruction-set>
|
</instruction-set>
|
||||||
|
|
||||||
|
<instruction-set targetVersion="2">
|
||||||
|
<add-channel id="endTime">
|
||||||
|
<type>roku:endTime</type>
|
||||||
|
</add-channel>
|
||||||
|
<add-channel id="progress">
|
||||||
|
<type>roku:progress</type>
|
||||||
|
</add-channel>
|
||||||
|
</instruction-set>
|
||||||
</thing-type>
|
</thing-type>
|
||||||
|
|
||||||
</update:update-descriptions>
|
</update:update-descriptions>
|
||||||
|
Loading…
Reference in New Issue
Block a user