Skip to content

Commit

Permalink
[roku] Add device communcation logging (openhab#17312)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Lobstein <michael.lobstein@gmail.com>
  • Loading branch information
mlobstein authored Aug 23, 2024
1 parent 1c7ef60 commit d18a6c1
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.openhab.binding.roku.internal.dto.TvChannel;
import org.openhab.binding.roku.internal.dto.TvChannels;
import org.openhab.binding.roku.internal.dto.TvChannels.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Methods for accessing the HTTP interface of the Roku
Expand All @@ -46,6 +48,7 @@
public class RokuCommunicator {
private static final int REQUEST_TIMEOUT = 5000;

private final Logger logger = LoggerFactory.getLogger(RokuCommunicator.class);
private final HttpClient httpClient;

private final String urlKeyPress;
Expand Down Expand Up @@ -114,6 +117,8 @@ public DeviceInfo getDeviceInfo() throws RokuHttpException {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_DEVICE_INFO;
if (ctx != null) {
final String response = getCommand(urlQryDevice);
logger.trace("Called {}, got response: {}", urlQryDevice, response);

Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Expand All @@ -140,6 +145,8 @@ public ActiveApp getActiveApp() throws RokuHttpException {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_ACTIVE_APP;
if (ctx != null) {
final String response = getCommand(urlQryActiveApp);
logger.trace("Called {}, got response: {}", urlQryActiveApp, response);

Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Expand All @@ -166,6 +173,8 @@ public List<App> getAppList() throws RokuHttpException {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_APPS;
if (ctx != null) {
final String response = getCommand(urlQryApps);
logger.trace("Called {}, got response: {}", urlQryApps, response);

Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Expand All @@ -192,6 +201,8 @@ public Player getPlayerInfo() throws RokuHttpException {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_PLAYER;
if (ctx != null) {
final String response = getCommand(urlQryPlayer);
logger.trace("Called {}, got response: {}", urlQryPlayer, response);

Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Expand All @@ -218,6 +229,8 @@ public TvChannel getActiveTvChannel() throws RokuHttpException {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_TVCHANNEL;
if (ctx != null) {
final String response = getCommand(urlQryActiveTvChannel);
logger.trace("Called {}, got response: {}", urlQryActiveTvChannel, response);

Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Expand All @@ -244,6 +257,8 @@ public List<Channel> getTvChannelList() throws RokuHttpException {
JAXBContext ctx = JAXBUtils.JAXBCONTEXT_TVCHANNELS;
if (ctx != null) {
final String response = getCommand(urlQryTvChannels);
logger.trace("Called {}, got response: {}", urlQryTvChannels, response);

Unmarshaller unmarshaller = ctx.createUnmarshaller();
if (unmarshaller != null) {
XMLStreamReader xsr = JAXBUtils.XMLINPUTFACTORY.createXMLStreamReader(new StringReader(response));
Expand Down Expand Up @@ -286,6 +301,7 @@ private String getCommand(String url) throws RokuHttpException {
*/
private void postCommand(String url) throws RokuHttpException {
try {
logger.trace("Sending POST command: {}", url);
httpClient.POST(url).method(HttpMethod.POST).timeout(REQUEST_TIMEOUT, TimeUnit.MILLISECONDS).send();
} catch (TimeoutException | ExecutionException e) {
throw new RokuHttpException("Error executing POST command, URL: " + url, e);
Expand Down

0 comments on commit d18a6c1

Please sign in to comment.