Skip to content

Commit 203463e

Browse files
committed
changes
1 parent f185826 commit 203463e

File tree

4 files changed

+24
-94
lines changed

4 files changed

+24
-94
lines changed

conf/html/shared/grafana/js/builder.js

+6-77
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,16 @@ var REST_URL = "/rest/items/";
1818
var SMARTHOME_GRAFANA_DEFAULTS = {
1919
// library
2020
debug: "false",
21-
render: "false",
2221
refresh: "0",
2322
// ESH sitemap
2423
sitemap: "default",
2524
// Grafana URL
2625
urlPrefix: "//" + auth_type + "grafana." + domain,
2726
panelPath: "/d-solo/",
28-
renderPanelPath: "/render/d-solo/",
2927
// Grafana panel parameters
3028
from: "now-1d",
3129
to: "now",
32-
theme: "dark",
33-
// Grafana render panel parameters
34-
width: "auto",
35-
height: "auto"
30+
theme: "dark"
3631
};
3732

3833
function resolveParam(params, name)
@@ -206,14 +201,10 @@ function GrafanaPanel(params)
206201
let frame = resolveParam(params, "frame");
207202
let urlPrefix = resolveParam(params, "urlPrefix");
208203
let panelPath = resolveParam(params, "panelPath");
209-
let renderPanelPath = resolveParam(params, "renderPanelPath");
210204
let libVars = {
211205
debug: {
212206
value: resolveParam(params, "debug")
213207
},
214-
render: {
215-
value: resolveParam(params, "render")
216-
},
217208
refresh: {
218209
value: resolveParam(params, "refresh")
219210
}
@@ -237,28 +228,18 @@ function GrafanaPanel(params)
237228
theme: {
238229
key: "theme",
239230
value: resolveParam(params, "theme")
240-
},
241-
width: {
242-
key: "width",
243-
value: resolveParam(params, "width")
244-
},
245-
height: {
246-
key: "height",
247-
value: resolveParam(params, "height")
248231
}
249232
};
250233

251234
function updateFrameSourceURL()
252235
{
253236
var debug = libVars.debug.value;
254-
var render = libVars.render.value;
255237
var refresh = libVars.refresh.value;
256238

257239
var iframe = document.getElementById(frame);
258-
var idocument = iframe.contentWindow.document;
259240

260241
var url = urlPrefix;
261-
url += render === "true" ? renderPanelPath : panelPath;
242+
url += panelPath;
262243
url += urlVars.dashboard.value;
263244

264245
var firstParameter = true;
@@ -267,63 +248,20 @@ function GrafanaPanel(params)
267248
var key = urlVars[uvKey].key;
268249
var value = urlVars[uvKey].value;
269250

270-
if( key === "width" )
271-
{
272-
value = render === "false" ? undefined : (value === "auto" ? idocument.body.clientWidth : value);
273-
}
274-
else if( key === "height" )
275-
{
276-
value = render === "false" ? undefined : (value === "auto" ? idocument.body.clientHeight : value);
277-
}
278-
279251
if( key !== undefined && value !== undefined )
280252
{
281253
url += (firstParameter ? "?" : "&") + key + "=" + value;
282254
firstParameter = false;
283255
}
284256
}
285257

286-
if( render === "true" )
287-
{
288-
// append cache busting parameter
289-
url += "&cacheBuster=" + Date.now();
290-
}
291-
// update frame content
292-
if( debug === "true" )
293-
{
294-
idocument.open();
295-
idocument.write("<a href=\"" + url + "\">" + url + "</a>");
296-
idocument.close();
297-
}
298-
else if( render === "true" )
299-
{
300-
var htmlUrl = url.replace(renderPanelPath, panelPath);
301-
idocument.open();
302-
idocument.write("<style>body{margin:0px}p{margin:0px}</style>");
303-
idocument.write("<p style=\"text-align:center;\"><a href=\"" + htmlUrl + "\"><img src=\"" + url + "\"></a></p>");
304-
idocument.close();
305-
}
306-
else if( document.getElementById(frame).src !== url )
258+
if( document.getElementById(frame).src !== url )
307259
{
308260
// replace the URL so changes are not added to the browser history
309261
iframe.contentWindow.location.replace(url);
310262
}
311-
312-
if( render === "true" && refresh > 0 )
313-
{
314-
refreshTimerId = setTimeout(updateFrameSourceURL, refresh);
315-
}
316263
}
317264

318-
function updateFrameOnResize()
319-
{
320-
clearTimeout(resizeTimerId);
321-
if( libVars.render.value === "true" && ( urlVars.width.value === "auto" || urlVars.height.value === "auto" ) )
322-
{
323-
resizeTimerId = setTimeout(updateFrameSourceURL, 500);
324-
}
325-
}
326-
327265
function updateVars(vars)
328266
{
329267
for( let [key, value] of Object.entries(vars) )
@@ -337,11 +275,6 @@ function GrafanaPanel(params)
337275
{
338276
if( params ) updateVars(params);
339277
updateFrameSourceURL();
340-
if( !initialized && libVars.render.value === "true" && ( urlVars.width.value === "auto" || urlVars.height.value === "auto" ) )
341-
{
342-
initialized = true;
343-
window.addEventListener("resize", updateFrameOnResize);
344-
}
345278
},
346279
}
347280
}
@@ -456,14 +389,10 @@ function GrafanaBuilder(panelConfigs)
456389
frame.id = "panel-" + uniqueId + "-frame";
457390
frame.className = "panel-frame";
458391
frame.scrolling = "no";
459-
frame.onload = function()
392+
frame.addEventListener("load", function()
460393
{
461-
var cssLink = this.contentWindow.document.createElement("link");
462-
cssLink.href = "//" + auth_type + "openhab." + domain + "/static/shared/grafana/css/grafana.css";
463-
cssLink.rel = "stylesheet";
464-
cssLink.type = "text/css";
465-
this.contentWindow.document.head.appendChild(cssLink);
466-
};
394+
this.contentWindow.postMessage({ type: "css", src: "//" + auth_type + "openhab." + domain + "/static/shared/grafana/css/grafana.css" }, "*");
395+
});
467396
div.appendChild(frame);
468397

469398
params["frame"] = frame.id;

conf/html/shared/habpanel/js/helper.js

+5-13
Original file line numberDiff line numberDiff line change
@@ -1397,31 +1397,23 @@ var mvInitializer = function(){
13971397
elem[0].style="visibility:hidden";
13981398
elem[0].addEventListener("load", function()
13991399
{
1400-
let element = elem[0].contentWindow.document.querySelector('main');
1401-
element.style="background: transparent !important;";
1402-
1403-
element = elem[0].contentWindow.document.querySelector('body');
1404-
element.style="background: transparent !important;";
1405-
14061400
elem[0].style="";
14071401

14081402
var css = '.mdl-form {';
14091403
css = css + "background-color: black !important;";
14101404
css = css + "color: white !important;";
14111405
css = css + "}";
1412-
css = css + "body { font-family: Roboto; }";
1413-
css = css + ".mdl-form__row {border-bottom: 1px solid rgba(38,191,117,.50);}";
1406+
css = css + "main { background: transparent !important; }";
1407+
css = css + "body { font-family: Roboto; background: transparent !important;}";
1408+
css = css + ".mdl-form__row {border-bottom: 1px solid rgba(38,191,117,.50); color: white !important; }";
14141409
css = css + ".mdl-form__label, .mdl-form__text, .mdl-form__value--text-link { font-size:17px; }";
14151410
css = css + ".mdl-layout__header { background-color: black !important; border-bottom: 1px solid rgba(38,191,117,.50);}";
14161411
css = css + ".mdl-slider__background-upper { background-color: white !important;}";
14171412
css = css + ".mdl-form input[type=range].is-lowest-value::-webkit-slider-thumb { background-color: white !important;}";
14181413
css = css + ".mdl-form input[type=range].is-lowest-value::-moz-range-thumb { background-color: white !important;}";
14191414
//css = css + ".mdl-layout__header { background-color: rgba(38,191,117,.1) !important; border-bottom: 1px solid rgba(38,191,117,.50);}";
1420-
1421-
var head = elem[0].contentWindow.document.getElementsByTagName('head')[0];
1422-
var style = elem[0].contentWindow.document.createElement('style');
1423-
style.appendChild(document.createTextNode(css));
1424-
head.appendChild(style);
1415+
1416+
elem[0].contentWindow.postMessage({ type: "css", content: css }, "*");
14251417
});
14261418
}
14271419
};

python/shared/actions.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
name = str(action_class.simpleName)
1313
setattr(_MODULE, name, action_class)
1414

15+
from org.openhab.core.model.script.actions import Audio
1516
from org.openhab.core.model.script.actions import Exec
1617
from org.openhab.core.model.script.actions import HTTP
18+
from org.openhab.core.model.script.actions import Log
1719
from org.openhab.core.model.script.actions import Ping
1820
from org.openhab.core.model.script.actions import ScriptExecution
19-
from org.openhab.core.model.script.actions import Log
21+
from org.openhab.core.model.script.actions import Semantics
2022
from org.openhab.core.model.script.actions import Transformation
23+
from org.openhab.core.model.script.actions import Voice
2124

22-
STATIC_IMPORTS = [Exec, HTTP, Log, Ping, ScriptExecution, Transformation]
25+
STATIC_IMPORTS = [Audio, Exec, HTTP, Log, Ping, ScriptExecution, Semantics, Transformation, Voice]
2326

2427
for action in STATIC_IMPORTS:
2528
name = str(action.simpleName)

python/shared/helper.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def scriptUnloaded():
5555
log.info("unload")
5656

5757
class rule(object):
58-
def __init__(self, name = None,profile=None):
58+
def __init__(self, name = None, profile=None):
5959
self.name = name
6060
self.profile = profile
6161

@@ -364,14 +364,20 @@ def getHistoricItemEntry(itemOrName, refDate):
364364
def getHistoricItemState(itemOrName, refDate):
365365
return getHistoricItemEntry(itemOrName, refDate).getState()
366366

367-
368367
def getMaxItemState(itemOrName, refDate):
369368
item = _getItem(itemOrName)
370369
historicState = PersistenceExtensions.maximumSince(item, refDate, "jdbc")
371370
if historicState is None:
372371
raise NotInitialisedException(u"Item max state for {} before {} not found".format(item.getName(),refDate))
373372
return historicState.getState()
374373

374+
def getMinItemState(itemOrName, refDate):
375+
item = _getItem(itemOrName)
376+
historicState = PersistenceExtensions.minimumSince(item, refDate, "jdbc")
377+
if historicState is None:
378+
raise NotInitialisedException(u"Item min state for {} before {} not found".format(item.getName(),refDate))
379+
return historicState.getState()
380+
375381

376382
# *** Item updates ***
377383
def _checkForUpdates(itemOrName, state):

0 commit comments

Comments
 (0)