diff --git a/fhem/contrib/YAF/FHEM/YAF/widgets/iteasylamp/iteasylamp.pm b/fhem/contrib/YAF/FHEM/YAF/widgets/iteasylamp/iteasylamp.pm new file mode 100644 index 000000000..6eab410b8 --- /dev/null +++ b/fhem/contrib/YAF/FHEM/YAF/widgets/iteasylamp/iteasylamp.pm @@ -0,0 +1,228 @@ +######################################################################################## +# +# iteasylamp.pm +# +# YAF - Yet Another Floorplan +# FHEM Projektgruppe Hochschule Karlsruhe, 2013 +# Markus Mangei, Daniel Weisensee, Prof. Dr. Peter A. Henning +# +######################################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +######################################################################################## +package main; + +use strict; +use warnings; + +my $yaf_version = 0.45; + +use vars qw(%_GET); +use vars qw(%defs); + +####################################################################################### +# +# iteasylamp_get_widgetcss - Create the CSS code for this widget +# +# no parameter +# +######################################################################################## + +sub iteasylamp_get_widgetcss() { + my $output = " + .widget_iteasylamp { + width: 33px; + height: 33px; + background-repeat:no-repeat; + background-position:center center; + opacity:1 !important; + } + + .widget_iteasylamp_on { + background-image:url(./img/lamp_on.png) !important; + } + + .widget_iteasylamp_off { + background-image:url(./img/lamp_off.png) !important; + } + "; + return $output; +} + +######################################################################################## +# +# iteasylamp_get_widgetjs - Create the javascript code for this widget +# +# no parameter +# +######################################################################################## + +sub iteasylamp_get_widgetjs() { + + my $output = ' + function iteasylamp_on_click(view_id, widget_id) { + var widget = $("#widget_"+view_id+"_"+widget_id); + var newState; + if (widget.hasClass("widget_iteasylamp_on")) { + newState = "off"; + } else{ + newState = "on"; + } + $.ajax({ + type: "GET", + async: true, + url: "../../ajax/widget/iteasylamp/set_lamp_status", + data: "view_id="+view_id+"&widget_id="+widget_id+"&status="+newState, + context: document.body, + success: function(){ + iteasylamp_update_widget(view_id, widget_id); + } + }); + } + + function iteasylamp_update_widget(view_id, widget_id) { + $.ajax({ + type: "GET", + async: true, + url: "../../ajax/widget/iteasylamp/get_lamp_status", + data: "view_id="+view_id+"&widget_id="+widget_id, + context: document.body, + success: function(lamp_status) { + var widget = $("#widget_"+view_id+"_"+widget_id); + if (lamp_status == "off") { + if (widget.hasClass("widget_iteasylamp_on")) { + widget.removeClass("widget_iteasylamp_on"); + } + if (!widget.hasClass("widget_iteasylamp_off")) { + widget.addClass("widget_iteasylamp_off"); + } + } + else if (lamp_status == "on") { + if (!widget.hasClass("widget_iteasylamp_on")) { + widget.addClass("widget_iteasylamp_on"); + } + if (widget.hasClass("widget_iteasylamp_off")) { + widget.removeClass("widget_iteasylamp_off"); + } + } + } + }); + } + '; + return $output; +} + +######################################################################################## +# +# iteasylamp_getwidgethtml - HTML code for this widget +# +# no parameter +# +######################################################################################## + +sub iteasylamp_get_widgethtml() { + my $output = ""; + return $output; +} + +######################################################################################## +# +# iteasylamp_get_addwidget_setup_html - Create the selection of devices for this widget +# +# no parameter +# +######################################################################################## + +sub iteasylamp_get_addwidget_setup_html() { + my $output = " + "; + + return $output; +} + +######################################################################################## +# +# iteasylamp_get_addwidget_prepare_attributes - +# +# no parameter +# +######################################################################################## + +sub iteasylamp_get_addwidget_prepare_attributes() { + my $output = ' + var temp_array = new Array(); + temp_array[0] = "fhemname"; + temp_array[1] = $("#combobox option:selected").val() + attributes_array[0] = temp_array; + '; + return $output; +} + +######################################################################################## +# +# iteasylamp_getwidget_html - HTML code for this widget. DO WE NEED THIS ? SEE ABOVE +# +# no parameter +# +######################################################################################## + +sub iteasylamp_getwidget_html() { + my $output = " "; + return $output; +} + +######################################################################################## +# +# iteasylamp_get_lamp_status - return the state of the lamp +# +# no parameter +# +######################################################################################## + +sub iteasylamp_get_lamp_status () { + my $attribute = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "fhemname"); + my $d = $defs{$attribute}; + return $d->{STATE}; +} + +######################################################################################## +# +# iteasylamp_set_lamp_status - set the state of the lamp +# +# no parameter +# +######################################################################################## + +sub iteasylamp_set_lamp_status() { + my $attribute = YAF_getWidgetAttribute($_GET{"view_id"}, $_GET{"widget_id"}, "fhemname"); + my $d = $defs{$attribute}; + Log 3, "set ".$d->{NAME}." ".$_GET{"status"}; + fhem "set ".$d->{NAME}." ".$_GET{"status"}; +} + +1; \ No newline at end of file diff --git a/fhem/contrib/YAF/controls_yaf.txt b/fhem/contrib/YAF/controls_yaf.txt index 6f3f933fa..536dc83c1 100644 --- a/fhem/contrib/YAF/controls_yaf.txt +++ b/fhem/contrib/YAF/controls_yaf.txt @@ -16,6 +16,8 @@ DIR FHEM/YAF/widgets/generic DIR FHEM/YAF/widgets/generic/www DIR FHEM/YAF/widgets/webcam DIR FHEM/YAF/widgets/webcam/www +DIR FHEM/YAF/widgets/iteasylamp +DIR FHEM/YAF/widgets/iteasylamp/www DIR FHEM/YAF/www DIR FHEM/YAF/www/css DIR FHEM/YAF/www/smoothness @@ -23,13 +25,14 @@ DIR FHEM/YAF/www/smoothness/images DIR FHEM/YAF/www/img DIR FHEM/YAF/www/js DIR FHEM/YAF/xml -UPD 2013-10-28_18:30:00 12229 FHEM/01_YAF.pm +UPD 2013-11-18:18:00:00 12436 FHEM/01_YAF.pm UPD 2013-05-15_20:00:00 6590 FHEM/YAF/widgets/fs20st/fs20st.pm UPD 2013-08-14_21:30:00 7471 FHEM/YAF/widgets/fht80/fht80.pm UPD 2013-07-31_15:30:00 6534 FHEM/YAF/widgets/fhttk/fhttk.pm UPD 2013-09-10_22:20:00 11387 FHEM/YAF/widgets/generic/generic.pm UPD 2013-09-16_16:50:00 6445 FHEM/YAF/widgets/webcam/webcam.pm UPD 2013-05-15_20:00:00 6617 FHEM/YAF/widgets/fs20easylamp/fs20easylamp.pm +UPD 2013-11-18:18:00:00 6547 FHEM/YAF/widgets/iteasylamp/iteasylamp.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 UPD 2013-05-15_20:00:00 19226 FHEM/YAF/www/img/background.png @@ -60,8 +63,8 @@ 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-09-12_22:30:00 16597 FHEM/YAF/YAFConfig.pm -UPD 2013-05-15_20:00:00 3439 FHEM/YAF/YAFWidgets.pm +UPD 2013-11-18:18:00:00 16597 FHEM/YAF/YAFConfig.pm +UPD 2013-11-18:18:00:00 3439 FHEM/YAF/YAFWidgets.pm UPD 2013-10-28_18:30:00 12649 FHEM/YAF/libs/json/Changes UPD 2013-10-28_18:30:00 68658 FHEM/YAF/libs/json/JSON.pm UPD 2013-10-28_18:30:00 1353 FHEM/YAF/libs/json/MANIFEST