mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 18:59:33 +00:00
YAFConfig: config loads without refreshing the page, code refactoring, fht80 feature: change size of text with "size" yaf-attribute (set "em" size like "size=0.6")
git-svn-id: https://svn.fhem.de/fhem/trunk@3522 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
e17dbb8baa
commit
3965b328b9
@ -31,6 +31,7 @@ my $yaf_version=0.41;
|
||||
|
||||
my %fhemwidgets;
|
||||
my %fhemviews;
|
||||
my $isInit = 0;
|
||||
|
||||
#######################################################################################
|
||||
#
|
||||
@ -44,7 +45,7 @@ my %fhemviews;
|
||||
sub YAF_FHEMConfig { #this is called via ajax when the page is loaded.
|
||||
#get the views
|
||||
my $views = AttrVal("yaf","views",undef);
|
||||
if(defined $views) {
|
||||
if(defined $views and $isInit == 0) {
|
||||
foreach my $view (split (/;/,$views)) {
|
||||
my @aview = split(/,/,$view);
|
||||
$fhemviews{$aview[0]} = $aview[1];
|
||||
@ -67,6 +68,9 @@ sub YAF_FHEMConfig { #this is called via ajax when the page is loaded.
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
Log 3, "YAF initialized";
|
||||
$isInit = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#######################################################################################
|
||||
@ -453,6 +457,7 @@ sub YAF_setWidgetPosition{
|
||||
# viewId - The view id to search
|
||||
# widgetId - The widget id
|
||||
# attributeName - name of the attribute properties to search for
|
||||
# default - Value to return on undefined
|
||||
#
|
||||
# @return The value property if successful, otherwise 0
|
||||
#
|
||||
@ -462,7 +467,12 @@ sub YAF_getWidgetAttribute{
|
||||
my $viewId = $_[0];
|
||||
my $widgetId = $_[1];
|
||||
my $attributeName = $_[2];
|
||||
my $default = (defined $_[3]) ? $_[3] : 0;
|
||||
|
||||
if($isInit == 0) { #after a restart of fhem the config hashes might be empty, because they are filled while
|
||||
YAF_FHEMConfig(); #loading the "yaf.htm" page. However, when restarting FHEM without reloading the page, there
|
||||
} #will be lots of errors. Since this method is called by any update method, we check if YAF
|
||||
#is initialized and load the config, if not.
|
||||
my $retAttr = "";
|
||||
my $widgetName = "";
|
||||
|
||||
@ -470,7 +480,7 @@ sub YAF_getWidgetAttribute{
|
||||
$widgetName = $fhemwidgets{$viewId}{$widgetId};
|
||||
}
|
||||
|
||||
if("fhemname" eq $attributeName) { #special case: get the fhemname
|
||||
if("fhemname" eq $attributeName) { #special case: get the fhemname
|
||||
$retAttr = $widgetName; #the key is the name of the device
|
||||
} else {
|
||||
my $attrString = AttrVal($widgetName,"yaf_$viewId",undef);
|
||||
@ -488,7 +498,7 @@ sub YAF_getWidgetAttribute{
|
||||
if(length $retAttr > 0) {
|
||||
return $retAttr; #return the found config
|
||||
} else {
|
||||
return 0;
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
@ -505,7 +515,7 @@ sub YAF_getRefreshTime{
|
||||
if (defined $ret) {
|
||||
return $ret;
|
||||
} else {
|
||||
Log 1,"YAF_getRefreshTime: refresh_interval attribute was not found (so it was created with a default value)";
|
||||
Log 1,"YAF_getRefreshTime: refresh_interval attribute was not found (so it will be created with a default value)";
|
||||
fhem("attr yaf refresh_interval 60");
|
||||
fhem("save");
|
||||
return 60;
|
||||
@ -527,7 +537,7 @@ sub YAF_setRefreshTime{
|
||||
#fhem("save");
|
||||
return 1;
|
||||
} else {
|
||||
Log 1,"YAF_setRefreshTime: no valid refresh value or refresh node was not found";
|
||||
Log 1,"YAF_setRefreshTime: no valid refresh value or refresh attribute was not found";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ use vars qw(%defs);
|
||||
#######################################################################################
|
||||
#
|
||||
# fht80_get_widgetcss - Create the CSS code for this widget
|
||||
#
|
||||
#
|
||||
# no parameter
|
||||
#
|
||||
########################################################################################
|
||||
@ -54,7 +54,7 @@ sub fht80_get_widgetcss() {
|
||||
text-align: center;
|
||||
}
|
||||
.widget_fht80_alias {
|
||||
font-size: 12px;
|
||||
font-size: 0.7em;
|
||||
}
|
||||
";
|
||||
return $output;
|
||||
@ -63,13 +63,13 @@ sub fht80_get_widgetcss() {
|
||||
########################################################################################
|
||||
#
|
||||
# fht80_get_widgetjs - Create the javascript code for this widget
|
||||
#
|
||||
#
|
||||
# no parameter
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub fht80_get_widgetjs() {
|
||||
|
||||
|
||||
my $output = '
|
||||
function fht80_update_widget(view_id, widget_id) {
|
||||
$.ajax({
|
||||
@ -78,10 +78,14 @@ sub fht80_get_widgetjs() {
|
||||
url: "../../ajax/widget/fht80/get_temp",
|
||||
data: "view_id="+view_id+"&widget_id="+widget_id,
|
||||
context: document.body,
|
||||
success: function(get_temp) {
|
||||
success: function(get_data) {
|
||||
var data = jQuery.parseJSON(get_data);
|
||||
var get_temp = data[0];
|
||||
var sizefac = data[1];
|
||||
var widget = $("#widget_"+view_id+"_"+widget_id);
|
||||
widget.css("font-size", sizefac+"em");
|
||||
widget.html(get_temp);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
';
|
||||
@ -91,7 +95,7 @@ sub fht80_get_widgetjs() {
|
||||
########################################################################################
|
||||
#
|
||||
# fht80t_getwidgethtml - HTML code for this widget
|
||||
#
|
||||
#
|
||||
# no parameter
|
||||
#
|
||||
########################################################################################
|
||||
@ -104,7 +108,7 @@ sub fht80_get_widgethtml() {
|
||||
########################################################################################
|
||||
#
|
||||
# fht80t_get_addwidget_setup_html - Create the selection of devices for this widget
|
||||
#
|
||||
#
|
||||
# no parameter
|
||||
#
|
||||
########################################################################################
|
||||
@ -113,19 +117,19 @@ sub fht80_get_addwidget_setup_html() {
|
||||
my $output = "<script src='js/combobox.js'></script>
|
||||
<select name='fht80_combobox' id='combobox'>";
|
||||
my @list = (keys %defs);
|
||||
|
||||
|
||||
foreach my $d (sort @list) {
|
||||
my $type = $defs{$d}{TYPE};
|
||||
my $name = $defs{$d}{NAME};
|
||||
|
||||
if( $type eq "FHT"){
|
||||
|
||||
|
||||
$output = $output."<option value='$name'>$name</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$output = $output."</select>";
|
||||
|
||||
|
||||
$output .= "<br /><label>Label:</label>
|
||||
<script src='js/combobox.js'></script>
|
||||
<select name='fht80_combobox_label' id='combobox_label'>";
|
||||
@ -133,14 +137,14 @@ sub fht80_get_addwidget_setup_html() {
|
||||
$output .= "<option value='Alias'>Alias</option>";
|
||||
$output .= "<option value='Comment'>Comment</option>";
|
||||
$output .= "</select>";
|
||||
|
||||
return $output;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# fht80t_get_addwidget_prepare_attributes -
|
||||
#
|
||||
# fht80t_get_addwidget_prepare_attributes -
|
||||
#
|
||||
# no parameter
|
||||
#
|
||||
########################################################################################
|
||||
@ -156,7 +160,7 @@ sub fht80_get_addwidget_prepare_attributes() {
|
||||
temp_array2[1] = $("#combobox_label option:selected").val()
|
||||
attributes_array[1] = temp_array2;
|
||||
';
|
||||
return $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
@ -164,71 +168,76 @@ sub fht80_get_addwidget_prepare_attributes() {
|
||||
# fht80t_getwidget_html - HTML code for this widget. DO WE NEED THIS ? SEE ABOVE
|
||||
# DO WE NEED IT? WHO KNOWS. (It looks like this one fills the initial html of the
|
||||
# widget, so let's keep it for science.)
|
||||
#
|
||||
#
|
||||
# no parameter
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub fht80_getwidget_html() {
|
||||
my $output = "###";
|
||||
return $output;
|
||||
return $output;
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
#
|
||||
# fht80t_get_lamp_status - return the state of the lamp
|
||||
#
|
||||
#
|
||||
# no parameter
|
||||
#
|
||||
########################################################################################
|
||||
|
||||
sub fht80_get_temp() {
|
||||
my $attribute = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "fhemname");
|
||||
if(!($attribute)) {
|
||||
return("Widget not found ".$_GET{"view_id"}." ".$_GET{"widget_id"});
|
||||
my @ret = ();
|
||||
my $viewid = $_GET{"view_id"};
|
||||
my $widgetid = $_GET{"widget_id"};
|
||||
my $fhemname = YAF_getWidgetAttribute($viewid, $widgetid, "fhemname", undef);
|
||||
|
||||
if(!defined $fhemname) {
|
||||
$ret[0] = "Widget not found " . $viewid . " " . $widgetid;
|
||||
$ret[1] = 1;
|
||||
return(encode_json(\@ret));
|
||||
}
|
||||
|
||||
my $labeltype = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "labeltype");
|
||||
|
||||
my $d = $defs{$attribute};
|
||||
my $ret = "";
|
||||
|
||||
my $temp = $defs{$attribute}{READINGS}{temperature}{VAL};
|
||||
my $temptimestamp = $defs{$attribute}{READINGS}{temperature}{TIME};
|
||||
my $actuator = $defs{$attribute}{READINGS}{actuator}{VAL};
|
||||
|
||||
# get all the needed data
|
||||
my $temp = fht80_isdef($defs{$fhemname}{READINGS}{temperature}{VAL}, 0);
|
||||
my $temptimestamp = fht80_isdef($defs{$fhemname}{READINGS}{temperature}{TIME}, "");
|
||||
my $actuator = fht80_isdef($defs{$fhemname}{READINGS}{actuator}{VAL}, "");
|
||||
my $mode = fht80_isdef($defs{$fhemname}{READINGS}{mode}{VAL}, "none");
|
||||
my $desi = fht80_isdef($defs{$fhemname}{READINGS}{"desired-temp"}{VAL}, "");
|
||||
my $battery = fht80_isdef($defs{$fhemname}{READINGS}{battery}{VAL}, "");
|
||||
my $nomode = YAF_getWidgetAttribute($viewid, $widgetid, "nomode", 0);
|
||||
my $labeltype = YAF_getWidgetAttribute($viewid, $widgetid, "labeltype", "");
|
||||
$ret[1] = YAF_getWidgetAttribute($viewid, $widgetid, "size", 1); #we don't process the size, so put it in the return array right away.
|
||||
|
||||
#process data
|
||||
my $label = "";
|
||||
if($labeltype eq "Comment") {
|
||||
$label = AttrVal($attribute,"comment",$d->{NAME});
|
||||
$label = AttrVal($fhemname,"comment",$fhemname);
|
||||
} elsif ($labeltype eq "Alias") {
|
||||
$label = AttrVal($attribute,"alias",$d->{NAME});
|
||||
$label = AttrVal($fhemname,"alias",$fhemname);
|
||||
} else {
|
||||
$label = $d->{NAME}
|
||||
$label = $fhemname;
|
||||
}
|
||||
$label =~ s/(_)/ /g;
|
||||
my $mode = $defs{$attribute}{READINGS}{mode}{VAL};
|
||||
my $desi = $defs{$attribute}{READINGS}{"desired-temp"}{VAL};
|
||||
my $battery = $defs{$attribute}{READINGS}{battery}{VAL};
|
||||
|
||||
if($mode eq "manual") {
|
||||
$mode = " <span title='manual'>⊕</span> ";
|
||||
} else {
|
||||
$mode = " <span title='$mode'>⊗</span> ";
|
||||
|
||||
$mode = ($mode eq "manual") ? " <span title='manual'>⊕</span>" : " <span title='$mode'>⊗</span>";
|
||||
$desi .= ($desi ne "off") ? " °C" : "";
|
||||
$battery = ($battery ne "ok") ? "Check Battery: " . $battery . "<br />" : "";
|
||||
|
||||
#create returnstring
|
||||
$ret[0] = "<span class='widget_fht80_alias'>" . $label . "</span><br />" . $battery;
|
||||
$ret[0] .= "<span title='$temptimestamp'>" . $temp . "</span>" . " °C";
|
||||
if($nomode == 0) {
|
||||
$ret[0] .= $mode;
|
||||
}
|
||||
|
||||
if($desi ne "off") {
|
||||
$desi .= " °C";
|
||||
$ret[0] .= " <span title='Actuator: $actuator'>" . $desi . "</span>";
|
||||
}
|
||||
|
||||
if($battery ne "ok") {
|
||||
$battery = "Check Battery: " . $battery . "<br />";
|
||||
} else {
|
||||
$battery = "";
|
||||
}
|
||||
|
||||
$ret = "<span class='widget_fht80_alias'>" . $label . "</span><br />" . $battery;
|
||||
$ret .= "<span title='$temptimestamp'>" . $temp . "</span>" . " °C" . $mode;
|
||||
$ret .= "<span title='Actuator: $actuator'>" . $desi . "</span>";
|
||||
|
||||
return $ret;
|
||||
|
||||
return encode_json(\@ret);
|
||||
}
|
||||
|
||||
sub fht80_isdef() {
|
||||
return ((defined $_[0]) ? $_[0] : $_[1]);
|
||||
}
|
||||
1;
|
||||
|
@ -82,7 +82,7 @@ sub fhttk_get_widgetjs() {
|
||||
context: document.body,
|
||||
success: function(get_state) {
|
||||
var widget = $("#widget_"+view_id+"_"+widget_id);
|
||||
$("#widget_"+view_id+"_"+widget_id).attr("title",get_state);
|
||||
$("#widget_"+view_id+"_"+widget_id).attr("title",get_state);
|
||||
if (endsWith(get_state,"Open")) {
|
||||
if (widget.hasClass("widget_fhttk_closed")) {
|
||||
widget.removeClass("widget_fhttk_closed");
|
||||
@ -90,6 +90,7 @@ sub fhttk_get_widgetjs() {
|
||||
if (!widget.hasClass("widget_fhttk_open")) {
|
||||
widget.addClass("widget_fhttk_open");
|
||||
}
|
||||
widget.html("<span />");
|
||||
}
|
||||
else if (endsWith(get_state,"Closed")) {
|
||||
if (!widget.hasClass("widget_fhttk_closed")) {
|
||||
@ -98,9 +99,10 @@ sub fhttk_get_widgetjs() {
|
||||
if (widget.hasClass("widget_fhttk_open")) {
|
||||
widget.removeClass("widget_fhttk_open");
|
||||
}
|
||||
widget.html("<span />");
|
||||
}
|
||||
else {
|
||||
widget.html("Error:"+get_state);
|
||||
widget.html("Error:"+get_state);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -193,14 +195,17 @@ sub fhttk_getwidget_html() {
|
||||
########################################################################################
|
||||
|
||||
sub fhttk_get_state() {
|
||||
my $attribute = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "fhemname");
|
||||
my $d = $defs{$attribute};
|
||||
my $fhemname = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "fhemname"); #get name of device
|
||||
my $d = $defs{$fhemname}; #get device
|
||||
my $name = AttrVal($fhemname,"alias",undef); #get alias
|
||||
if(!defined $name) { #if alias is defined, use it as name
|
||||
$name = $fhemname;
|
||||
}
|
||||
if(defined $d) {
|
||||
my $ret = $attribute.": ".trim($d->{STATE});
|
||||
my $ret = $name.": ".$d->{STATE}; #return "name: state"
|
||||
return $ret;
|
||||
} else {
|
||||
return "Widget not found. Maybe reload this page?";
|
||||
return "<span onClick=document.location.reload(true)>Widget not found. Maybe reload this page?</span>";
|
||||
}
|
||||
}
|
||||
1;
|
||||
|
||||
1;
|
@ -17,8 +17,8 @@ DIR FHEM/YAF/www/js
|
||||
DIR FHEM/YAF/xml
|
||||
UPD 2013-07-23_20:45:00 11477 FHEM/01_YAF.pm
|
||||
UPD 2013-05-15_20:00:00 6590 FHEM/YAF/widgets/fs20st/fs20st.pm
|
||||
UPD 2013-07-20_16:00:00 6869 FHEM/YAF/widgets/fht80/fht80.pm
|
||||
UPD 2013-07-23_20:45:00 6095 FHEM/YAF/widgets/fht80/fhttk.pm
|
||||
UPD 2013-07-28_17:00:00 6869 FHEM/YAF/widgets/fht80/fht80.pm
|
||||
UPD 2013-07-28_17:00:00 6095 FHEM/YAF/widgets/fht80/fhttk.pm
|
||||
UPD 2013-05-15_20:00:00 6617 FHEM/YAF/widgets/fs20easylamp/fs20easylamp.pm
|
||||
UPD 2013-05-15_20:00:00 2608 FHEM/YAF/www/img/loading.gif
|
||||
UPD 2013-05-15_20:00:00 766 FHEM/YAF/www/img/lamp_off.png
|
||||
@ -50,5 +50,5 @@ UPD 2013-05-15_20:00:00 101 FHEM/YAF/www/css/smoothness/images/ui-bg_highlight-s
|
||||
UPD 2013-05-15_20:00:00 26086 FHEM/YAF/www/css/smoothness/jquery-ui-1.9.1.custom.min.css
|
||||
UPD 2013-05-15_20:00:00 3641 FHEM/YAF/xml/xmlSchema.xsd
|
||||
UPD 2013-05-15_20:00:00 1690 FHEM/YAF/xml/yafConfig.xml
|
||||
UPD 2013-07-23_20:45:00 14744 FHEM/YAF/YAFConfig.pm
|
||||
UPD 2013-07-28_17:00:00 14744 FHEM/YAF/YAFConfig.pm
|
||||
UPD 2013-05-15_20:00:00 3439 FHEM/YAF/YAFWidgets.pm
|
||||
|
Loading…
Reference in New Issue
Block a user