diff --git a/fhem/contrib/YAF/FHEM/YAF/YAFConfig.pm b/fhem/contrib/YAF/FHEM/YAF/YAFConfig.pm
index c9c5b47e9..657339e59 100644
--- a/fhem/contrib/YAF/FHEM/YAF/YAFConfig.pm
+++ b/fhem/contrib/YAF/FHEM/YAF/YAFConfig.pm
@@ -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;
}
}
diff --git a/fhem/contrib/YAF/FHEM/YAF/widgets/fht80/fht80.pm b/fhem/contrib/YAF/FHEM/YAF/widgets/fht80/fht80.pm
index 9647a49f5..e14f02b49 100644
--- a/fhem/contrib/YAF/FHEM/YAF/widgets/fht80/fht80.pm
+++ b/fhem/contrib/YAF/FHEM/YAF/widgets/fht80/fht80.pm
@@ -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 = "
";
-
+
$output .= "
";
-
- 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 = " ⊕ ";
- } else {
- $mode = " ⊗ ";
+
+ $mode = ($mode eq "manual") ? " ⊕" : " ⊗";
+ $desi .= ($desi ne "off") ? " °C" : "";
+ $battery = ($battery ne "ok") ? "Check Battery: " . $battery . "
" : "";
+
+ #create returnstring
+ $ret[0] = "" . $label . "
" . $battery;
+ $ret[0] .= "" . $temp . "" . " °C";
+ if($nomode == 0) {
+ $ret[0] .= $mode;
}
-
if($desi ne "off") {
- $desi .= " °C";
+ $ret[0] .= " " . $desi . "";
}
-
- if($battery ne "ok") {
- $battery = "Check Battery: " . $battery . "
";
- } else {
- $battery = "";
- }
-
- $ret = "" . $label . "
" . $battery;
- $ret .= "" . $temp . "" . " °C" . $mode;
- $ret .= "" . $desi . "";
-
- return $ret;
+
+ return encode_json(\@ret);
+}
+
+sub fht80_isdef() {
+ return ((defined $_[0]) ? $_[0] : $_[1]);
}
1;
diff --git a/fhem/contrib/YAF/FHEM/YAF/widgets/fhttk/fhttk.pm b/fhem/contrib/YAF/FHEM/YAF/widgets/fhttk/fhttk.pm
index 033fe2e96..4706d36c6 100644
--- a/fhem/contrib/YAF/FHEM/YAF/widgets/fhttk/fhttk.pm
+++ b/fhem/contrib/YAF/FHEM/YAF/widgets/fhttk/fhttk.pm
@@ -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("");
}
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("");
}
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 "Widget not found. Maybe reload this page?";
}
}
-1;
-
+1;
\ No newline at end of file
diff --git a/fhem/contrib/YAF/controls_yaf.txt b/fhem/contrib/YAF/controls_yaf.txt
index 22785a2aa..17af5e97b 100644
--- a/fhem/contrib/YAF/controls_yaf.txt
+++ b/fhem/contrib/YAF/controls_yaf.txt
@@ -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