Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kodi] Added dynamic state descriptions for opening pvr stream channels #3207

Merged

Conversation

cweitkamp
Copy link
Contributor

@cweitkamp cweitkamp commented Feb 4, 2018

  • Added dynamic state descriptions for opening pvr stream channels
  • Added REQUEST_CACHE
  • Added model for Kodi specific entities (e.g. KodiPVRChannelGroup, KodiPVRChannel, KodiBaseItem, etc.)
  • Adapted README.md

Also-by: Gregory Moyer [email protected]
Signed-off-by: Christoph Weitkamp [email protected]

@cweitkamp
Copy link
Contributor Author

@mhilbush You can return the favor - if you like. ;-)

Copy link
Contributor

@mhilbush mhilbush 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 minor comments. Sorry for the delay in getting to this.

JsonElement response = socket.callMethod("PVR.GetChannelGroups", params);
String method = "PVR.GetChannelGroups";
String hash = method + "#channeltype=" + channelType;
if (!REQUEST_CACHE.containsKey(hash)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

JsonElement response = socket.callMethod("PVR.GetChannels", params);
String method = "PVR.GetChannels";
String hash = method + "#channelgroupid=" + channelGroupID;
if (!REQUEST_CACHE.containsKey(hash)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above.

KodiChannelConfig config = getThing().getChannel(channelUID.getId()).getConfiguration()
.as(KodiChannelConfig.class);
playPVRChannel(command, "tv", config);
playPVRChannel(command, "tv", CHANNEL_PVR_OPEN_TV);
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize it was like this already, but should tv and radio be defined as constants, as they seem to be used elsewhere in the code?

KodiChannelConfig config = getThing().getChannel(channelUID.getId()).getConfiguration()
.as(KodiChannelConfig.class);
playPVRChannel(command, "radio", config);
playPVRChannel(command, "radio", CHANNEL_PVR_OPEN_RADIO);
Copy link
Contributor

Choose a reason for hiding this comment

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

See above comment.

Signed-off-by: Christoph Weitkamp <[email protected]>
Signed-off-by: Christoph Weitkamp <[email protected]>
…com:cweitkamp/openhab2-addons into feature-kodi-pvr-dynamic-state-descriptions
Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp cweitkamp force-pushed the feature-kodi-pvr-dynamic-state-descriptions branch from 5a2756d to 9b49743 Compare February 8, 2018 09:38
Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp cweitkamp changed the title [WIP][Kodi] Added dynamic state descriptions for opening pvr stream channels [Kodi] Added dynamic state descriptions for opening pvr stream channels Feb 8, 2018
@cweitkamp
Copy link
Contributor Author

@mhilbush Thanks for your first review. I finished my work. Can you check it again?

Copy link
Contributor

@mhilbush mhilbush left a comment

Choose a reason for hiding this comment

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

@cweitkamp Just a few minor comments. Otherwise, LGTM.

if (response instanceof JsonObject) {
JsonObject result = response.getAsJsonObject();
if (result.has("channelgroups")) {
return result.get("channelgroups").getAsJsonArray();
for (JsonElement element : result.get("channelgroups").getAsJsonArray()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The old code checks to see if the member channelgroups exists in the response. Not being familiar with the protocol, was that check unnecessary? If it's not there, won't this line generate a NPE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case it is not crucial. There is always one default channel group of each channel type.

if (response instanceof JsonObject) {
JsonObject result = response.getAsJsonObject();
if (result.has("channels")) {
return result.get("channels").getAsJsonArray();
for (JsonElement element : result.get("channels").getAsJsonArray()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above concerning the assumption that the response always will contain the member channels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case it is crucial. The field is missing if a channel group doesn't contain any channels. Thanks for the hint. I changed it in both cases.

/**
* The PVR channel id
*/
private int channelId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Very minor, but noting slight inconsistency in naming. Here it is channelId and getId. Elsewhere it's channelID and getChannelID. I might not even bring this up, except that elsewhere in the code channelId refers to the ESH channelId.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true. I think about a renaming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it and feel that my naming is OK in thus place. But I changed it in the rest of the binding to have a clear line when we talk about an ESH channel or a TV channel.

return channelGroupId;
}

public void setId(final int channelGroupId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also channelGroupId is referred to as channelGroupID elsewhere in the code (e.g. the method getChannelGroupID).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See above.

Selection item=myKodi_pvropentv mappings=[Add your PVR TV channels here ...]
Selection item=myKodi_pvropenchannel mappings=[Add your PVR radio channels here ...]
Selection item=myKodi_pvropentv
Selection item=myKodi_pvropenchannel
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this depends on this feature being implemented in ESH, is the intention to delay the merge of this until that feature is part of a future ESH stable?

Also, WDYT about a HABpanel Selection widget example, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes and No. The example was bad before. But since it depends on the users configuration of Kodi I can't think of a better one.

WDYT about a HABpanel Selection widget example

Hm, ... I wouldn't support that. IMHO the documentation should be independent and not related to any UI. Shouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, yes, the documentation should be independent of the UI. OTOH, the downside is that it forces the user to figure it out on their own, or to hunt on the forum for someone who's already done it.

My motive for asking was purely selfish, as I was struggling with this exact question for the squeezebox favorites. ;-)

Signed-off-by: Christoph Weitkamp <[email protected]>
…aning of PVR and ESH channel

Signed-off-by: Christoph Weitkamp <[email protected]>
@cweitkamp
Copy link
Contributor Author

@martinvw may I ask you to have a look at this PR? It's already reviewed. Thank you.

Copy link
Member

@martinvw martinvw left a comment

Choose a reason for hiding this comment

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

Only some nitpicking 😄

@@ -60,9 +64,13 @@

private ScheduledFuture<?> statusUpdaterFuture;

public KodiHandler(@NonNull Thing thing) {
private KodiDynamicStateDescriptionProvider stateDescriptionProvider;
Copy link
Member

Choose a reason for hiding this comment

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

Final?

/**
* The label of the item
*/
protected String label;
Copy link
Member

Choose a reason for hiding this comment

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

Why protected can it be private

@@ -50,6 +51,8 @@
.asList(new Integer[] { -32, -16, -8, -4, -2, 1, 2, 4, 8, 16, 32 });
private static final ExpiringCacheMap<String, RawType> IMAGE_CACHE = new ExpiringCacheMap<>(
TimeUnit.MINUTES.toMillis(15)); // 15min
private static final ExpiringCacheMap<String, JsonElement> REQUEST_CACHE = new ExpiringCacheMap<>(
TimeUnit.MINUTES.toMillis(5)); // 5min
Copy link
Member

Choose a reason for hiding this comment

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

Is the comment still needed when using the TimeUnit?

}
public int getPVRChannelId(final int pvrChannelGroupId, final String pvrChannelName) {
List<KodiPVRChannel> pvrChannels = getPVRChannels(pvrChannelGroupId);
for (KodiPVRChannel pvrChannel : pvrChannels) {
Copy link
Member

@martinvw martinvw Feb 22, 2018

Choose a reason for hiding this comment

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

I think that I would not assign this first to a var

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean exactly?
for (KodiPVRChannel pvrChannel : getPVRChannels(pvrChannelGroupId)) { instead?

Copy link
Member

Choose a reason for hiding this comment

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

Yes

Signed-off-by: Christoph Weitkamp <[email protected]>
Signed-off-by: Christoph Weitkamp <[email protected]>
Signed-off-by: Christoph Weitkamp <[email protected]>
@martinvw martinvw merged commit 4a25680 into openhab:master Feb 23, 2018
@cweitkamp cweitkamp deleted the feature-kodi-pvr-dynamic-state-descriptions branch February 23, 2018 13:42
@cweitkamp
Copy link
Contributor Author

Thank you all.

@@ -37,5 +37,6 @@ Import-Package:
org.openhab.binding.kodi.handler,
org.osgi.framework,
org.osgi.service.component,
org.osgi.service.component.annotations,
Copy link
Member

Choose a reason for hiding this comment

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

FTR: this should not be done like this, see also #3292 & #3294

@martinvw martinvw added this to the 2.3 milestone May 25, 2018
@martinvw martinvw added the enhancement An enhancement or new feature for an existing add-on label May 25, 2018
divyachauhan25 pushed a commit to divyachauhan25/openhab2-addons that referenced this pull request Jul 6, 2018
…ls (openhab#3207)

* Changed README.md
* Added dynamic state descriptions for opening pvr stream channels
* Added model for Kodi specific entities
* Added NPE safeguard

Signed-off-by: Christoph Weitkamp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants