-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Kodi] Added dynamic state descriptions for opening pvr stream channe…
…ls (#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]>
- Loading branch information
Showing
10 changed files
with
298 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../src/main/java/org/openhab/binding/kodi/internal/KodiDynamicStateDescriptionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...nhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/model/KodiBaseItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/model/KodiPVRChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
/** | ||
* 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; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...nding.kodi/src/main/java/org/openhab/binding/kodi/internal/model/KodiPVRChannelGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
this.channelGroupId = channelGroupId; | ||
} | ||
|
||
public String getChannelType() { | ||
return channelType; | ||
} | ||
|
||
public void setChannelType(final String channelType) { | ||
this.channelType = channelType; | ||
} | ||
} |
Oops, something went wrong.