这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.

Conversation

@giig1967g
Copy link
Contributor

I hope this time is fine

Committing change for xbmc binding
sending my changes to XBMC binding.

Added following commands:
- Player.GETINFO
- Player.GETPROPERTIES
- XBMC.GetINFOLABEL

Added configurable refresh interval
public void activate() {
logger.debug(getName() + " activate()");
setProperlyConfigured(true);
//setProperlyConfigured(true); // <-Removed as it has been moved to the "updated" call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the commented code - the history will be retained in github.

I added several hundred commands to xbmc binding.

1) can send all 192 input commands supported by Input.ExecuteActions JSON call directly from the items file using Input.ExecuteAction.<<command>>
List of commands are in list 1 below.
Source: http://kodi.wiki/view/JSON-RPC_API/v6#Input.Action
Usage: {xbmc=">[#xbmcinstance|Input.ExecuteAction.<<commandname>>"}
Examples:
Switch sXBMC_SHOWOSD   		"XBMCosd" {xbmc=">[#kodisalotto|Input.ExecuteAction.osd]"}
Switch sXBMC_UP        		"XBMCup"  {xbmc=">[#kodisalotto|Input.ExecuteAction.up]"}
Switch sXBMC_ASPECTRATIO    "XBMCar"  {xbmc=">[#kodisalotto|Input.ExecuteAction.aspectratio]"}
Switch sXBMC_TOGGLESCREEN  	"XBMCtf"  {xbmc=">[#kodisalotto|Input.ExecuteAction.togglefullscreen]"}

2) can read all 23 Player.Property.Name values:
List of commands in list 2 below.
Source: http://kodi.wiki/view/JSON-RPC_API/v6#Player.Property.Name
Usage: {xbmc="<[#xbmcinstance|Property.<<propertyName>>"}
Examples:
String sXBMC2  "XBMC2 [%s]"   	{xbmc="<[#kodisalotto|Property.Type]"}
String sXBMC3  "XBMC3 [%s %%]"  {xbmc="<[#kodisalotto|Property.Percentage]"}
String sXBMC4  "XBMC4 [%s]"   	{xbmc="<[#kodisalotto|Property.Time]"}
String sXBMC5  "XBMC5 [%s]"   	{xbmc="<[#kodisalotto|Property.TotalTime]"}
String sXBMC6  "XBMC6 [%s]"   	{xbmc="<[#kodisalotto|Property.CurrentSubtitle]"}

3) can Retrieve info labels about Kodi and the system using XBMC.GetInfoLabels
List of possible commands in: http://kodi.wiki/index.php?title=InfoLabels (there are hundreds)
Usage: {xbmc="<[#xbmcinstance|Label.<<infolabelname>>"}
Examples:
String sXBMC7  "XBMC7 [%s]"   {xbmc="<[#kodisalotto|Label.VideoPlayer.Title]"}
String sXBMC8  "XBMC8 [%s]"   {xbmc="<[#kodisalotto|Label.Player.Time]"}
String sXBMC9  "XBMC9 [%s]"   {xbmc="<[#kodisalotto|Label.VideoPlayer.VideoResolution]"}
String sXBMC10 "XBMC10 [%s]"  {xbmc="<[#kodisalotto|Label.VideoPlayer.VideoCodec]"}
String sXBMC11 "XBMC11 [%s]"  {xbmc="<[#kodisalotto|Label.System.Uptime]"}

list1:
    left
    right
    up
    down
    pageup
    pagedown
    select
    highlight
    parentdir
    parentfolder
    back
    previousmenu
    info
    pause
    stop
    skipnext
    skipprevious
    fullscreen
    aspectratio
    stepforward
    stepback
    bigstepforward
    bigstepback
    osd
    showsubtitles
    nextsubtitle
    codecinfo
    nextpicture
    previouspicture
    zoomout
    zoomin
    playlist
    queue
    zoomnormal
    zoomlevel1
    zoomlevel2
    zoomlevel3
    zoomlevel4
    zoomlevel5
    zoomlevel6
    zoomlevel7
    zoomlevel8
    zoomlevel9
    nextcalibration
    resetcalibration
    analogmove
    rotate
    rotateccw
    close
    subtitledelayminus
    subtitledelay
    subtitledelayplus
    audiodelayminus
    audiodelay
    audiodelayplus
    subtitleshiftup
    subtitleshiftdown
    subtitlealign
    audionextlanguage
    verticalshiftup
    verticalshiftdown
    nextresolution
    audiotoggledigital
    number0
    number1
    number2
    number3
    number4
    number5
    number6
    number7
    number8
    number9
    osdleft
    osdright
    osdup
    osddown
    osdselect
    osdvalueplus
    osdvalueminus
    smallstepback
    fastforward
    rewind
    play
    playpause
    delete
    copy
    move
    mplayerosd
    hidesubmenu
    screenshot
    rename
    togglewatched
    scanitem
    reloadkeymaps
    volumeup
    volumedown
    mute
    backspace
    scrollup
    scrolldown
    analogfastforward
    analogrewind
    moveitemup
    moveitemdown
    contextmenu
    shift
    symbols
    cursorleft
    cursorright
    showtime
    analogseekforward
    analogseekback
    showpreset
    presetlist
    nextpreset
    previouspreset
    lockpreset
    randompreset
    increasevisrating
    decreasevisrating
    showvideomenu
    enter
    increaserating
    decreaserating
    togglefullscreen
    nextscene
    previousscene
    nextletter
    prevletter
    jumpsms2
    jumpsms3
    jumpsms4
    jumpsms5
    jumpsms6
    jumpsms7
    jumpsms8
    jumpsms9
    filter
    filterclear
    filtersms2
    filtersms3
    filtersms4
    filtersms5
    filtersms6
    filtersms7
    filtersms8
    filtersms9
    firstpage
    lastpage
    guiprofile
    red
    green
    yellow
    blue
    increasepar
    decreasepar
    volampup
    volampdown
    channelup
    channeldown
    previouschannelgroup
    nextchannelgroup
    leftclick
    rightclick
    middleclick
    doubleclick
    wheelup
    wheeldown
    mousedrag
    mousemove
    noop

list 2:
	canrepeat
	canmove
	canshuffle
	speed
	percentage
	playlistid
	audiostreams
	position
	repeat
	currentsubtitle
	canrotate
	canzoom
	canchangespeed
	type
	partymode
	subtitles
	canseek
	time
	totaltime
	shuffled
	currentaudiostream
	live
	subtitleenabled
@sumnerboy12
Copy link
Contributor

Looks ok to me, if you have tested it and are happy it works then I am happy to approve it. The only other thing to do would be to update the WIKI page for this binding with instructions on how to use all the new actions. Thanks very much!

Copy link
Contributor

@watou watou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few issues with comments and logging.

* @author tlan, Ben Jones
* @since 1.5.0
* @author tlan, Ben Jones, Plebs
* @since 1.9.0
Copy link
Contributor

@watou watou Sep 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just add your name to the existing @author tag for files you've changed, and leave the @since tag as is. So in the case of this file, no changes are warranted.

* @author tlan, Ben Jones
* @since 1.5.0
* @author tlan, Ben Jones, Plebs
* @since 1.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just add your name to the existing @author tag for files you've changed, and leave the @since tag as is.

* @author tlan, Ben Jones
* @since 1.5.0
* @author tlan, Ben Jones, Plebs
* @since 1.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just add your name to the existing @author tag for files you've changed, and leave the @since tag as is. So in the case of this file, no changes are warranted.

* @author tlan, Ben Jones
* @since 1.5.0
* @author tlan, Ben Jones, Plebs
* @since 1.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just add your name to the existing @author tag for files you've changed, and leave the @since tag as is. So in the case of this file, no changes are warranted.

* @author tlan, Ben Jones
* @since 1.5.0
* @author tlan, Ben Jones, Plebs
* @since 1.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just add your name to the existing @author tag for files you've changed, and leave the @since tag as is.

* @since 1.5.0
* @author tlan, Ben Jones, Plebs
* @since 1.9.0
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you added this file, the comment should just be

 * @author Plebs
 * @since 1.9.0

}

Map<String, Object> params = new HashMap<String, Object>();
// params.put("playerid", playerId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code lines.

@Override
protected void processResponse(Map<String, Object> response) {
Map<String, Object> result = getMap(response, "result");
// item = getMap(result, "label");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code lines.

* @author Ben Jones
* @since 1.5.0
* @author Plebs
* @since 1.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment tags should just be

 * @author Ben Jones, Plebs
 * @since 1.5.0

@Override
protected void processResponse(Map<String, Object> response) {
Map<String, Object> result = getMap(response, "result");
// item = getMap(result, "item");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code lines.

Also added a new command: "Refresh" to asynch refresh the labels coming from XBMC
@giig1967g
Copy link
Contributor Author

Hi,
I sent the files with the changes suggested.
Sorry for the confusion with the tags, but it's the first time I actually
give a contribution to an Open Source app so please apologies.

I have also added a new command in the meantime...
"Refresh"

On 20 September 2016 at 12:09, John Cocula notifications@github.com wrote:

@watou requested changes on this pull request.

Just a few issues with comments and logging.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/internal/XbmcActivator.java
#4622 (review):

@@ -18,6 +18,9 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file, no

changes are warranted.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/internal/XbmcActiveBinding.java
#4622 (review):

@@ -34,8 +35,10 @@
*

Please just add your name to the existing @author tag for files you've

changed, and leave the @SInCE tag as is.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/internal/XbmcGenericBindingProvider.java
#4622 (review):

@@ -25,6 +25,8 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file, no

changes are warranted.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/internal/XbmcHost.java
#4622 (review):

@@ -13,6 +13,8 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file, no

changes are warranted.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

@@ -37,6 +37,8 @@
*

Please just add your name to the existing @author tag for files you've

changed, and leave the @SInCE tag as is.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

@@ -131,11 +133,14 @@ private void postRequest(Map<String, Object> request, Runnable completeHandler)
try {
// we fire this request off asynchronously and let the completeHandler
// process any response as necessary (can be null)

  •        logger.debug("Write JSON: " + writeJson(request)); // Stefano: logging the JSON request
    

While this works, it's a little confusing because someone might think
writeJson only happens when debug is active. Consider something like this
instead:

String result = writeJson(request);
logger.debug("Write JSON: {}", result);


In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

         ListenableFuture<Response> future = client.preparePost(uri).setBody(writeJson(request))
                 .setHeader("content-type", "application/json").setHeader("accept", "application/json")
                 .execute(new AsyncCompletionHandler<Response>() {
                     @Override
                     public Response onCompleted(Response response) throws Exception {
  •                        logger.debug("Read JSON: " + response.getResponseBody()); // Stefano: logging the JSON
    
  •                                                                                  // response
    

Use parameterized logging to avoid unnecessary string concatenation:

logger.debug("Read JSON: {}", response.getResponseBody());


In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

@@ -63,6 +65,8 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file,

only update the existing @author tag.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  */
 public void addItem(String itemName, String property) {
  •    logger.debug("Mapping: itemname=" + itemName + " & property = " + property);
    

Use parameterized logging, like:

logger.debug("Mapping: itemname={} & property = {}", itemName, property);


In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  •            }
    
  •        }
    
  •        // make the request for the player item details using GETINFO
    
  •        if (!propertiesInfo.isEmpty()) {
    
  •            final PlayerGetItem item = new PlayerGetItem(client, httpUri);
    
  •            item.setPlayerId(playerId);
    
  •            item.setProperties(propertiesInfo);
    
  •            item.execute(new Runnable() {
    
  •                @Override
    
  •                public void run() {
    
  •                    // now update each of the openHAB items for each property
    
  •                    for (String property : propertiesInfo) {
    
  •                        String value = item.getPropertyValue(property);
    
  •                        // logger.debug("UPDATEfromGETINFO: property=" + property + " & value=" + value);
    

Either remove the commented out code, or uncomment the debug line (and

switch to parameterized logging).

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  •            });
    
  •        }
    
  •        // make the request for the player item2 details using GETPROPERTIES
    
  •        if (!propertiesProperties.isEmpty()) {
    
  •            final PlayerGetProperties item2 = new PlayerGetProperties(client, httpUri);
    
  •            item2.setPlayerId(playerId);
    
  •            item2.setProperties(propertiesProperties);
    
  •            item2.execute(new Runnable() {
    
  •                @Override
    
  •                public void run() {
    
  •                    // now update each of the openHAB items for each property
    
  •                    for (String property : propertiesProperties) {
    
  •                        String value = item2.getPropertyValue(property);
    
  •                        // logger.debug("UPDATEfromGETPROPERTIES: property=" + property + " & value=" + value);
    

Either remove the commented out code, or uncomment the debug line (and

switch to parameterized logging).

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

                         updateProperty(property, value);
                     }
                 }
  •            }
    
  •        });
    
  •            });
    
  •        }
    
  •        // make the request for the player item3 details using GETLABELS
    
  •        if (!propertiesLabels.isEmpty()) {
    
  •            final PlayerGetLabels item3 = new PlayerGetLabels(client, httpUri);
    
  •            // item3.setPlayerId(playerId);
    

Remove the commented out code.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  •            });
    
  •        }
    
  •        // make the request for the player item3 details using GETLABELS
    
  •        if (!propertiesLabels.isEmpty()) {
    
  •            final PlayerGetLabels item3 = new PlayerGetLabels(client, httpUri);
    
  •            // item3.setPlayerId(playerId);
    
  •            item3.setProperties(propertiesLabels);
    
  •            item3.execute(new Runnable() {
    
  •                @Override
    
  •                public void run() {
    
  •                    // now update each of the openHAB items for each property
    
  •                    for (String property : propertiesLabels) {
    
  •                        String value = item3.getPropertyValue(property);
    
  •                        // logger.debug("UPDATEfromGETLABELS: property=" + property + " & value=" + value);
    

Either remove the commented out code, or uncomment the debug line (and

switch to parameterized logging).

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/calls/PlayerGetItem.java
#4622 (review):

@@ -23,6 +23,8 @@
*

Just add your name to line 24 (and add back Marcel Erkel), and leave it at

1.5.0, and remove lines 26 & 27.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/calls/PlayerGetLabels.java
#4622 (review):

+import org.apache.commons.lang.StringUtils;
+import org.openhab.binding.xbmc.rpc.RpcCall;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ning.http.client.AsyncHttpClient;
+
+/**

Since you added this file, the comment should just be


In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/calls/PlayerGetLabels.java
#4622 (review):

  • protected String getName() {
  •    return "XBMC.GetInfoLabels";
    
  • }
  • @OverRide
  • protected Map<String, Object> getParams() {
  •    List<String> paramProperties = new ArrayList<String>();
    
  •    for (String property : properties) {
    
  •        if (property.startsWith("Label.")) {
    
  •            String paramProperty = getParamProperty(property);
    
  •            paramProperties.add(paramProperty);
    
  •        }
    
  •    }
    
  •    Map<String, Object> params = new HashMap<String, Object>();
    
  •    // params.put("playerid", playerId);
    

Remove commented code lines.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/calls/PlayerGetLabels.java
#4622 (review):

  •        if (property.startsWith("Label.")) {
    
  •            String paramProperty = getParamProperty(property);
    
  •            paramProperties.add(paramProperty);
    
  •        }
    
  •    }
    
  •    Map<String, Object> params = new HashMap<String, Object>();
    
  •    // params.put("playerid", playerId);
    
  •    params.put("labels", paramProperties);
    
  •    return params;
    
  • }
  • @OverRide
  • protected void processResponse(Map<String, Object> response) {
  •    Map<String, Object> result = getMap(response, "result");
    
  •    // item = getMap(result, "label");
    

Remove commented code lines.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/calls/PlayerGetProperties.java
#4622 (review):

import com.ning.http.client.AsyncHttpClient;

/**

Comment tags should just be


In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/calls/PlayerGetProperties.java
#4622 (review):

     return params;
 }
 @Override
 protected void processResponse(Map<String, Object> response) {
     Map<String, Object> result = getMap(response, "result");
  •    // item = getMap(result, "item");
    

Remove commented code lines.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4622 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUVJ093zBu6mYNShy1GuttTSsVg2Zszkks5qr7DAgaJpZM4J1TtJ
.

@giig1967g
Copy link
Contributor Author

Hi all,
did you have a chance to merge my changes?
Please keep me updated and then I will update the wiki.

On 20 September 2016 at 20:54, STEFANO FRANCO franco.stefano@gmail.com
wrote:

Hi,
I sent the files with the changes suggested.
Sorry for the confusion with the tags, but it's the first time I actually
give a contribution to an Open Source app so please apologies.

I have also added a new command in the meantime...
"Refresh"

On 20 September 2016 at 12:09, John Cocula notifications@github.com
wrote:

@watou requested changes on this pull request.

Just a few issues with comments and logging.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/internal/XbmcActivator.java
#4622 (review):

@@ -18,6 +18,9 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file, no

changes are warranted.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/internal/XbmcActiveBinding.java
#4622 (review):

@@ -34,8 +35,10 @@
*

Please just add your name to the existing @author tag for files you've

changed, and leave the @SInCE tag as is.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/internal/XbmcGenericBindingProvider.java
#4622 (review):

@@ -25,6 +25,8 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file, no

changes are warranted.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/internal/XbmcHost.java
#4622 (review):

@@ -13,6 +13,8 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file, no

changes are warranted.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

@@ -37,6 +37,8 @@
*

Please just add your name to the existing @author tag for files you've

changed, and leave the @SInCE tag as is.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

@@ -131,11 +133,14 @@ private void postRequest(Map<String, Object> request, Runnable completeHandler)
try {
// we fire this request off asynchronously and let the completeHandler
// process any response as necessary (can be null)

  •        logger.debug("Write JSON: " + writeJson(request)); // Stefano: logging the JSON request
    

While this works, it's a little confusing because someone might think
writeJson only happens when debug is active. Consider something like
this instead:

String result = writeJson(request);
logger.debug("Write JSON: {}", result);


In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

         ListenableFuture<Response> future = client.preparePost(uri).setBody(writeJson(request))
                 .setHeader("content-type", "application/json").setHeader("accept", "application/json")
                 .execute(new AsyncCompletionHandler<Response>() {
                     @Override
                     public Response onCompleted(Response response) throws Exception {
  •                        logger.debug("Read JSON: " + response.getResponseBody()); // Stefano: logging the JSON
    
  •                                                                                  // response
    

Use parameterized logging to avoid unnecessary string concatenation:

logger.debug("Read JSON: {}", response.getResponseBody());


In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

@@ -63,6 +65,8 @@
*

Please just add your name to the existing @author tag for files you've
changed, and leave the @SInCE tag as is. So in the case of this file,

only update the existing @author tag.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  */
 public void addItem(String itemName, String property) {
  •    logger.debug("Mapping: itemname=" + itemName + " & property = " + property);
    

Use parameterized logging, like:

logger.debug("Mapping: itemname={} & property = {}", itemName, property);


In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  •            }
    
  •        }
    
  •        // make the request for the player item details using GETINFO
    
  •        if (!propertiesInfo.isEmpty()) {
    
  •            final PlayerGetItem item = new PlayerGetItem(client, httpUri);
    
  •            item.setPlayerId(playerId);
    
  •            item.setProperties(propertiesInfo);
    
  •            item.execute(new Runnable() {
    
  •                @Override
    
  •                public void run() {
    
  •                    // now update each of the openHAB items for each property
    
  •                    for (String property : propertiesInfo) {
    
  •                        String value = item.getPropertyValue(property);
    
  •                        // logger.debug("UPDATEfromGETINFO: property=" + property + " & value=" + value);
    

Either remove the commented out code, or uncomment the debug line (and

switch to parameterized logging).

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  •            });
    
  •        }
    
  •        // make the request for the player item2 details using GETPROPERTIES
    
  •        if (!propertiesProperties.isEmpty()) {
    
  •            final PlayerGetProperties item2 = new PlayerGetProperties(client, httpUri);
    
  •            item2.setPlayerId(playerId);
    
  •            item2.setProperties(propertiesProperties);
    
  •            item2.execute(new Runnable() {
    
  •                @Override
    
  •                public void run() {
    
  •                    // now update each of the openHAB items for each property
    
  •                    for (String property : propertiesProperties) {
    
  •                        String value = item2.getPropertyValue(property);
    
  •                        // logger.debug("UPDATEfromGETPROPERTIES: property=" + property + " & value=" + value);
    

Either remove the commented out code, or uncomment the debug line (and

switch to parameterized logging).

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

                         updateProperty(property, value);
                     }
                 }
  •            }
    
  •        });
    
  •            });
    
  •        }
    
  •        // make the request for the player item3 details using GETLABELS
    
  •        if (!propertiesLabels.isEmpty()) {
    
  •            final PlayerGetLabels item3 = new PlayerGetLabels(client, httpUri);
    
  •            // item3.setPlayerId(playerId);
    

Remove the commented out code.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  •            });
    
  •        }
    
  •        // make the request for the player item3 details using GETLABELS
    
  •        if (!propertiesLabels.isEmpty()) {
    
  •            final PlayerGetLabels item3 = new PlayerGetLabels(client, httpUri);
    
  •            // item3.setPlayerId(playerId);
    
  •            item3.setProperties(propertiesLabels);
    
  •            item3.execute(new Runnable() {
    
  •                @Override
    
  •                public void run() {
    
  •                    // now update each of the openHAB items for each property
    
  •                    for (String property : propertiesLabels) {
    
  •                        String value = item3.getPropertyValue(property);
    
  •                        // logger.debug("UPDATEfromGETLABELS: property=" + property + " & value=" + value);
    

Either remove the commented out code, or uncomment the debug line (and

switch to parameterized logging).

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/calls/PlayerGetItem.java
#4622 (review):

@@ -23,6 +23,8 @@
*

Just add your name to line 24 (and add back Marcel Erkel), and leave it

at 1.5.0, and remove lines 26 & 27.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/calls/PlayerGetLabels.java
#4622 (review):

+import org.apache.commons.lang.StringUtils;
+import org.openhab.binding.xbmc.rpc.RpcCall;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.ning.http.client.AsyncHttpClient;
+
+/**

Since you added this file, the comment should just be


In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/calls/PlayerGetLabels.java
#4622 (review):

  • protected String getName() {
  •    return "XBMC.GetInfoLabels";
    
  • }
  • @OverRide
  • protected Map<String, Object> getParams() {
  •    List<String> paramProperties = new ArrayList<String>();
    
  •    for (String property : properties) {
    
  •        if (property.startsWith("Label.")) {
    
  •            String paramProperty = getParamProperty(property);
    
  •            paramProperties.add(paramProperty);
    
  •        }
    
  •    }
    
  •    Map<String, Object> params = new HashMap<String, Object>();
    
  •    // params.put("playerid", playerId);
    

Remove commented code lines.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/calls/PlayerGetLabels.java
#4622 (review):

  •        if (property.startsWith("Label.")) {
    
  •            String paramProperty = getParamProperty(property);
    
  •            paramProperties.add(paramProperty);
    
  •        }
    
  •    }
    
  •    Map<String, Object> params = new HashMap<String, Object>();
    
  •    // params.put("playerid", playerId);
    
  •    params.put("labels", paramProperties);
    
  •    return params;
    
  • }
  • @OverRide
  • protected void processResponse(Map<String, Object> response) {
  •    Map<String, Object> result = getMap(response, "result");
    
  •    // item = getMap(result, "label");
    

Remove commented code lines.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/calls/PlayerGetProperties.java
#4622 (review):

import com.ning.http.client.AsyncHttpClient;

/**

Comment tags should just be


In bundles/binding/org.openhab.binding.xbmc/src/main/java/org/
openhab/binding/xbmc/rpc/calls/PlayerGetProperties.java
#4622 (review):

     return params;
 }
 @Override
 protected void processResponse(Map<String, Object> response) {
     Map<String, Object> result = getMap(response, "result");
  •    // item = getMap(result, "item");
    

Remove commented code lines.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4622 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUVJ093zBu6mYNShy1GuttTSsVg2Zszkks5qr7DAgaJpZM4J1TtJ
.

Copy link
Contributor

@watou watou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a few more minor comments and a question on thread safety in calling execute() from different threads. If the above is addressed and some other XBMC/Kodi binding user can help verify proper function, I'd say it should be mergeable. Thanks for this PR.

// process any response as necessary (can be null)
ListenableFuture<Response> future = client.preparePost(uri).setBody(writeJson(request))
String resultWrite = writeJson(request);
logger.debug("Write JSON: {}", resultWrite ); // Stefano: logging the JSON request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the code through the Eclipse IDE formatter so future changes don't reformat lines with incorrect formatting.

.execute(new AsyncCompletionHandler<Response>() {
@Override
public Response onCompleted(Response response) throws Exception {
logger.debug("Read JSON: {}", response.getResponseBody()); // Stefano: logging the JSON response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the code through the Eclipse IDE formatter so future changes don't reformat lines with incorrect formatting.

*
*/
public void addItem(String itemName, String property) {
logger.debug("Mapping: itemname = {} & property = {}", itemName, property);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the code through the Eclipse IDE formatter so future changes don't reformat lines with incorrect formatting.

} else if (property.equals("PVR.OpenRadio")) {
connector.playerOpenPVR(command.toString(), 1);
} else if (property.equals("Refresh")) {
execute();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you certain that it is threadsafe to do this? The execute() method is called at some refreshInterval in another thread, so it may be possible that this method could be run from each thread overlapping. You might consider using a technique like in the HTTP or Ecobee binding, where the execute() method is called based on a short granularity (five seconds, for example), but checks a future timestamp to see if it should do anything. The "Refresh" action would then just expire the future timestamp, so the next scheduled execute happens on average granulary/2 into the future. The execute() method would just set the future timestamp to the current timestamp + refreshInterval. (There are certainly other sound approaches to avoiding thread safety issues.)

* Player.GetProperties RPC
*
* @author Ben Jones
* @author Ben jones, Plebs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jones

@watou watou added this to the 1.9.0 milestone Sep 28, 2016
@giig1967g
Copy link
Contributor Author

Hi all,
I don't understand what I am supposed to do...

Do I have to reformat the single line in the 3 files and resend to you? Or
you do it?

Regarding the refresh() method, I didn't want to change the original
structure of the binding.
In the original binding the excute() method is already called asyncronously
by a timer and by specific events, and can be overlapping. I just added a
manual call.
The Kodi JSON can handle cuncurrent calls with no issues at all.
I wouldn't know how to change it, so if what I added is a problem, I can
remove the manual refresh command.
Just tell me what do you prefer.

What are the next steps?

thanks
stefano

On 28 September 2016 at 15:39, John Cocula notifications@github.com wrote:

@watou commented on this pull request.

I've added a few more minor comments and a question on thread safety in
calling execute() from different threads. If the above is addressed and
some other XBMC/Kodi binding user can help verify proper function, I'd say

it should be mergeable. Thanks for this PR.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

@@ -131,11 +131,14 @@ private void postRequest(Map<String, Object> request, Runnable completeHandler)
try {
// we fire this request off asynchronously and let the completeHandler
// process any response as necessary (can be null)

  •        ListenableFuture<Response> future = client.preparePost(uri).setBody(writeJson(request))
    
  •        String resultWrite = writeJson(request);
    
  •     logger.debug("Write JSON: {}", resultWrite ); // Stefano: logging the JSON request
    

Please put the code through the Eclipse IDE formatter so future changes

don't reformat lines with incorrect formatting.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/RpcCall.java
#4622 (review):

                 .setHeader("content-type", "application/json").setHeader("accept", "application/json")
                 .execute(new AsyncCompletionHandler<Response>() {
                     @Override
                     public Response onCompleted(Response response) throws Exception {
  •                     logger.debug("Read JSON: {}", response.getResponseBody()); // Stefano: logging the JSON response
    

Please put the code through the Eclipse IDE formatter so future changes

don't reformat lines with incorrect formatting.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/XbmcConnector.java
#4622 (review):

  */
 public void addItem(String itemName, String property) {
  • logger.debug("Mapping: itemname = {} & property = {}", itemName, property);
    

Please put the code through the Eclipse IDE formatter so future changes

don't reformat lines with incorrect formatting.

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/internal/XbmcActiveBinding.java
#4622 (review):

@@ -326,6 +328,8 @@ protected void internalReceiveCommand(String itemName, Command command) {
connector.playerOpenPVR(command.toString(), 2);
} else if (property.equals("PVR.OpenRadio")) {
connector.playerOpenPVR(command.toString(), 1);

  •        } else if (property.equals("Refresh")) {
    
  •            execute();
    

Are you certain that it is threadsafe to do this? The execute() method is
called at some refreshInterval in another thread, so it may be possible
that this method could be run from each thread overlapping. You might
consider using a technique like in the HTTP or Ecobee binding, where the
execute() method is called based on a short granularity (five seconds,
for example), but checks a future timestamp to see if it should do
anything. The "Refresh" action would then just expire the future timestamp,
so the next scheduled execute happens on average granulary/2 into the
future. The execute() method would just set the future timestamp to the
current timestamp + refreshInterval. (There are certainly other sound

approaches to avoiding thread safety issues.)

In bundles/binding/org.openhab.binding.xbmc/src/main/java/
org/openhab/binding/xbmc/rpc/calls/PlayerGetProperties.java
#4622 (review):

import com.ning.http.client.AsyncHttpClient;

/**

  • Player.GetProperties RPC
    *

Jones


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4622 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AUVJ09xaDikLW7uMs6dMqmCjluclU_7Vks5qum4XgaJpZM4J1TtJ
.

@watou
Copy link
Contributor

watou commented Oct 6, 2016

In the original binding the excute() method is already called asyncronously by a timer and by specific events, and can be overlapping. I just added a manual call.

My comment was just to verify that this PR wasn't introducing a new thread safety issue. If other parts of the binding invoke execute() explicitly, then your change is probably OK.

So I will merge this now, and make a new PR myself to only correct the minor formatting issues.

@watou watou merged commit 76388ef into openhab:master Oct 6, 2016
@watou
Copy link
Contributor

watou commented Oct 6, 2016

@giig1967g Please update the wiki to document your new enhancements. Thanks!

@giig1967g
Copy link
Contributor Author

Hi watou,
I need an advice...
I was about to start modifying the wiki but then I realized that the new features will not be available to all, but just to the ones who download the nightly build (SNAPSHOT).

So, I think that the options are three:

  1. change the wiki now (but it might confuse the users who have not downloaded the latest version)
  2. change the wiki only when the next public version of OpenHAB will become available (1.9)
  3. change the wiki specifying that some changes will only be available for the SNAPSHOT users.

What is the best practice?

thanks

@watou
Copy link
Contributor

watou commented Oct 9, 2016

Hi Stefano, it's OK to update the wiki now, but please indicate which features will be available in version 1.9 and later of the binding, which will be the next official release that contains your enhancements. So the wiki will still be helpful to 1.8 users, but they won't be confused about which features they don't have if they are marked something like "available in 1.9."

@giig1967g
Copy link
Contributor Author

ok. thanks for the tip.

stefano

On 9 October 2016 at 12:24, John Cocula notifications@github.com wrote:

Hi Stefano, it's OK to update the wiki now, but please indicate which
features will be available in version 1.9 and later of the binding, which
will be the next official release that contains your enhancements. So the
wiki will still be helpful to 1.8 users, but they won't be confused about
which features they don't have if they are marked something like "available
in 1.9."


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#4622 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AUVJ0-eynPsSs96g_qWialXcZ-j3OaAqks5qyMDHgaJpZM4J1TtJ
.

cdjackson added a commit to cdjackson/openhab1-addons that referenced this pull request Oct 9, 2016
* master: (30 commits)
  [satel] Fixed refresh after control command (openhab#4674)
  [IPX800] Add binding to OH2 distro (openhab#4684)
  Database update (openhab#4692)
  ZWave database update (openhab#4679)
  [xbmc] Minor formatting (openhab#4683)
  some changes to XBMC binding (openhab#4622)
  [telegram] sendTelegramPhoto caption should be UTF-8 (openhab#4650)
  New api url for forecastio provider (openhab#4677)
  Review 1: Patch for: Error on startup with SQLite openhab#4652 (openhab#4670)
  [Plugwise] Fix Circles not always calibrated (openhab#4669)
  Database update (openhab#4664)
  [garadget] Remove misleading text on exception logs (openhab#4663)
  Fixes openhab#4635 (openhab#4649)
  [Plugwise] NullPointerException may occur when concurrent threads get PlugwiseDevice from Stick (openhab#4648)
  insteonplm binding: added mini remote 2342-222 (openhab#4641)
  [modbus] Connection timeout parameter for TCP slaves. (openhab#4627)
  [Plugwise] Add openHAB 2 feature addon (openhab#4644)
  fixes build problems
  [Plugwise] Add support for Scan, Sense, Stealth and Switch openhab#4565 (openhab#4586)
  [satel] Added rule action to set user code (openhab#4634)
  ...
@giig1967g
Copy link
Contributor Author

Hi,
I have updated the wiki.
Would appreciate if you check if the way I have done it is correct.

thanks

@watou
Copy link
Contributor

watou commented Oct 10, 2016

Thanks @giig1967g! Comments on your wiki changes:

  • Username to connect to XBMC. (optional, defaults to none)

  • Username to connect to XBMC. (optional, defaults to xbmc)

xbmc:livingRoom.username=xbmc

  • Password to connect to XBMC. (optional, defaults to none)

  • Password to connect to XBMC. (optional, defaults to xbmc)

xbmc:livingRoom.password=xbmc

I am concerned that this change to the binding will break existing users' configurations. Every PR should not break any existing configurations unless critically necessary. If this is a breaking change, it and the wiki should be reverted. What are your thoughts?

Available properties (until V1.8)

I suggest that you only label features that are new in 1.9 as such, and remove any references to 1.8 that you added if nothing about the feature has changed from 1.8 to 1.9.

+canrepeat | < | Returns true if the media can be repeated

When you say true, what is actually being returned? ON? OPEN?

+Examples:
+* xbmc=">[livingRoom|Player.PlayStop]"
+* xbmc="<[livingRoom|Player.Title]"

I think the examples would be more helpful if they showed a complete Item definition, as one would have in a .items file. That way, the user knows better what item type is being used, a label string could in some cases add more context, etc.

@giig1967g
Copy link
Contributor Author

Hi John,
Thanks for your comments.
Regarding the username/password change, I didn't change the code.
The wiki and the .cfg were wrong. In the code the default username and
password have always been set to "xbmc"/"xbmc".
I just documented it and updated the cfg file.

You can check in github.com.

You are right about the wiki regarding the expected returned text for the
properties.
Will update it.
When I have done, I will ask a again for your feedback :)

Thanks for your tips.

Il 10/Ott/2016 18:59, "John Cocula" notifications@github.com ha scritto:

Thanks @giig1967g https://github.com/giig1967g! Comments on your wiki
changes:

  • Username to connect to XBMC. (optional, defaults to none)

  • Username to connect to XBMC. (optional, defaults to xbmc)

    xbmc:livingRoom.username=xbmc
  • Password to connect to XBMC. (optional, defaults to none)

  • Password to connect to XBMC. (optional, defaults to xbmc)

    xbmc:livingRoom.password=xbmc

I am concerned that this change to the binding will break existing users'
configurations. Every PR should not break any existing configurations
unless critically necessary. If this is a breaking change, it and the wiki
should be reverted. What are your thoughts?

Available properties (until V1.8)

I suggest that you only label features that are new in 1.9 as such, and
remove any references to 1.8 that you added if nothing about the feature
has changed from 1.8 to 1.9.

+canrepeat | < | Returns true if the media can be repeated

When you say true, what is actually being returned? ON? OPEN?

+Examples:
+* xbmc=">[livingRoom|Player.PlayStop]"
+* xbmc="<[livingRoom|Player.Title]"

I think the examples would be more helpful if they showed a complete Item
definition, as one would have in a .items file. That way, the user knows
better what item type is being used, a label string could in some cases add
more context, etc.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#4622 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AUVJ028h0vq0zHWWuZ3QOS5pFrV-ahwMks5qym8MgaJpZM4J1TtJ
.

@watou
Copy link
Contributor

watou commented Oct 10, 2016

Regarding the username/password change, I didn't change the code. The wiki and the .cfg were wrong. In the code the default username and password have always been set to "xbmc"/"xbmc". I just documented it and updated the cfg file.

That's the best possible answer. Thanks for fixing the documentation.

You are right about the wiki regarding the expected returned text for the properties.
Will update it. When I have done, I will ask a again for your feedback :)

Perfect. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants