-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Kodi] Added dynamic state descriptions for opening pvr stream channels #3207
Conversation
Signed-off-by: Christoph Weitkamp <[email protected]>
@mhilbush You can return the favor - if you like. ;-) |
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use REQUEST_CACHE.putIfAbsentAndGet
here?
https://github.com/eclipse/smarthome/blob/4204ce06bb28c28e5f711e720f87ef83beff2e27/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/cache/ExpiringCacheMap.java#L116
JsonElement response = socket.callMethod("PVR.GetChannels", params); | ||
String method = "PVR.GetChannels"; | ||
String hash = method + "#channelgroupid=" + channelGroupID; | ||
if (!REQUEST_CACHE.containsKey(hash)) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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]>
5a2756d
to
9b49743
Compare
Signed-off-by: Christoph Weitkamp <[email protected]>
@mhilbush Thanks for your first review. I finished my work. Can you check it again? |
There was a problem hiding this 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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]>
@martinvw may I ask you to have a look at this PR? It's already reviewed. Thank you. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]>
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…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]>
REQUEST_CACHE
KodiPVRChannelGroup
,KodiPVRChannel
,KodiBaseItem
, etc.)Also-by: Gregory Moyer [email protected]
Signed-off-by: Christoph Weitkamp [email protected]