-
-
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
Changes from all commits
1259a40
4e658c0
f1cf030
cddc17f
9b49743
da43a3c
d2d64a7
4a93828
fd61b7a
a435f61
c2f2efc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2010-2018 by the respective copyright holders. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.kodi.internal; | ||
|
||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.eclipse.smarthome.core.thing.Channel; | ||
import org.eclipse.smarthome.core.thing.ChannelUID; | ||
import org.eclipse.smarthome.core.thing.type.DynamicStateDescriptionProvider; | ||
import org.eclipse.smarthome.core.types.StateDescription; | ||
import org.eclipse.smarthome.core.types.StateOption; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
|
||
/** | ||
* Dynamic provider of state options while leaving other state description fields as original. | ||
* | ||
* @author Gregory Moyer - Initial contribution | ||
* @author Christoph Weitkamp - Adapted to Kodi binding | ||
*/ | ||
@Component(service = { DynamicStateDescriptionProvider.class, | ||
KodiDynamicStateDescriptionProvider.class }, immediate = true) | ||
@NonNullByDefault | ||
public class KodiDynamicStateDescriptionProvider implements DynamicStateDescriptionProvider { | ||
private final Map<ChannelUID, List<StateOption>> channelOptionsMap = new ConcurrentHashMap<>(); | ||
|
||
public void setStateOptions(ChannelUID channelUID, List<StateOption> options) { | ||
channelOptionsMap.put(channelUID, options); | ||
} | ||
|
||
@Override | ||
public @Nullable StateDescription getStateDescription(Channel channel, @Nullable StateDescription original, | ||
@Nullable Locale locale) { | ||
List<StateOption> options = channelOptionsMap.get(channel.getUID()); | ||
if (options == null) { | ||
return null; | ||
} | ||
|
||
if (original != null) { | ||
return new StateDescription(original.getMinimum(), original.getMaximum(), original.getStep(), | ||
original.getPattern(), original.isReadOnly(), options); | ||
} | ||
|
||
return new StateDescription(null, null, null, null, false, options); | ||
} | ||
|
||
@Deactivate | ||
public void deactivate() { | ||
channelOptionsMap.clear(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright (c) 2010-2018 by the respective copyright holders. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.kodi.internal.model; | ||
|
||
/** | ||
* Class representing a Kodi base item | ||
* | ||
* @author Christoph Weitkamp - Initial contribution | ||
*/ | ||
public abstract class KodiBaseItem { | ||
/** | ||
* The label of the item | ||
*/ | ||
private String label; | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(final String label) { | ||
this.label = label; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) 2010-2018 by the respective copyright holders. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.kodi.internal.model; | ||
|
||
/** | ||
* Class representing a Kodi PVR channel | ||
* | ||
* @author Christoph Weitkamp - Initial contribution | ||
*/ | ||
public class KodiPVRChannel extends KodiBaseItem { | ||
/** | ||
* The PVR channel id | ||
*/ | ||
private int channelId; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very minor, but noting slight inconsistency in naming. Here it is There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
/** | ||
* The PVR channel group id | ||
*/ | ||
private int channelGroupId; | ||
|
||
public int getId() { | ||
return channelId; | ||
} | ||
|
||
public void setId(int channelId) { | ||
this.channelId = channelId; | ||
} | ||
|
||
public int getChannelGroupId() { | ||
return channelGroupId; | ||
} | ||
|
||
public void setChannelGroupId(int channelGroupId) { | ||
this.channelGroupId = channelGroupId; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2010-2018 by the respective copyright holders. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.openhab.binding.kodi.internal.model; | ||
|
||
/** | ||
* Class representing a Kodi PVR channel group | ||
* | ||
* @author Christoph Weitkamp - Initial contribution | ||
*/ | ||
public class KodiPVRChannelGroup extends KodiBaseItem { | ||
/** | ||
* The PVR channel group id | ||
*/ | ||
private int channelGroupId; | ||
|
||
/** | ||
* The PVR channel type | ||
*/ | ||
private String channelType; | ||
|
||
public int getId() { | ||
return channelGroupId; | ||
} | ||
|
||
public void setId(final int channelGroupId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
this.channelGroupId = channelGroupId; | ||
} | ||
|
||
public String getChannelType() { | ||
return channelType; | ||
} | ||
|
||
public void setChannelType(final String channelType) { | ||
this.channelType = channelType; | ||
} | ||
} |
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.
FTR: this should not be done like this, see also #3292 & #3294