I am trying to build a HABpanel widget to control my Harmony Hub. I would like to have a dropdown with all the current activities and I have that working, but the list is hardcodet in the widget. I would like the list to be fetched directly from the hub itself.
I found out that the channel-types rest api provides the list I need, but now I need to fill this list into the widget.
I am trying to do at http config to hold the URL for the channel-type.
harmonyHubActivities.url=http://openhabianpi:8080/rest/channel-types/harmonyhub%3Ahub%3AHarmonyHub%3AcurrentActivity
harmonyHubActivities.updateInterval=60000
{
"parameters": [],
"parameterGroups": [],
"description": "Current activity for HarmonyHub Harmony Hub",
"label": "Current Activity",
"itemType": "String",
"kind": "STATE",
"stateDescription": {
"pattern": "%s",
"readOnly": false,
"options": [
{
"value": "PowerOff",
"label": "PowerOff"
},
{
"value": "Watch TV",
"label": "Watch TV"
},
{
"value": "Play Xbox",
"label": "Play Xbox"
},
]
},
"tags": [],
"UID": "harmonyhub:hub:HarmonyHub:currentActivity",
"advanced": false
}
Then I have created an item that calls some js to pass the JSON and return a list.
String harmonyHubActivities "Harmony Hub activities [%s]" { http="<[harmonyHubActivities:60000:JS(getHarmonyHubActivities.js)]" }
(function(i) {
var json = JSON.parse(i);
return (json["stateDescription"]["options"]);
})(input)
Right now the script return the full json. I would like to just get the options list. And then I would like to pass the list to the widget instead of the static list sceneMap.
<div ng-init="sceneMap={
'PowerOff' : 'PowerOff',
'Watch TV' : 'Watch TV',
'Play Xbox' : 'Play Xbox',
}" />
<div style="width: 100%;" class="btn-group" uib-dropdown>
<button id="single-button" type="button" class="action-button" uib-dropdown-toggle>
<span id="hub-select">{{sceneMap[itemValue(config.hub)]}}</span><span class="caret" id="hue-controller-caret"></span>
<span id="hub-select" ng-if="sceneMap[itemValue(config.hub)]== NULL">UNKNOWN ({{itemValue(config.hub)}})</span>
</button>
<ul class="dropdown-menu" id="hub-controller-dropdown" uib-dropdown-menu role="menu" aria-labelledby="single-button">
<li role="menuitem" ng-repeat="(state, label) in sceneMap">
<a ng-click="sendCmd(config.hub, state)">{{label}}</a>
</li>
</ul>
</div>
I’m not that skilled in javascript and json parsing, so how do get the list from the json, and how do I get it into the widget?
And also I would like to know, if there is an easier way to get this list from the hub.