DevelopmentFHEMWEB: Unterschied zwischen den Versionen
(FW_docdir removed,) |
K (Von html- auf wiki-Formatierung geändert, Forenlink korrigiert, weitere kleinere Änderungen) |
||
Zeile 1: | Zeile 1: | ||
This page describes the FHEMWEB module from a developer's perspective. | This page describes the [[FHEMWEB]] module from a developer's perspective. | ||
= Global Variables = | == Global Variables == | ||
The following global variables are used throughout FHEMWEB, and should be used if you are extending it: | The following global variables are used throughout FHEMWEB, and should be used if you are extending it: | ||
;$FW_ME | |||
:When using FHEMWEB, you have to specify a base path in all requests; this value is stored in the variable $FW_ME and defaults to /fhem. The user may change it by setting the webname attribute. | |||
;$FW_dir | |||
:base directory from which FHEMWEB serves files. Defaults to $attr{global}{modpath}/www. | |||
;$FW_icondir | |||
:base directory from which FHEMWEB serves icons. Defaults to $FW_dir/images. | |||
;$FW_cssdir | |||
:base directory from which FHEMWEB serves HTML and SVG style sheets and javascript files. Defaults to $FW_dir/pgm2. | |||
;$FW_gplotdir | |||
:base directory where FHEMWEB searches for gplot files. Defaults to $FW_dir/gplot. | |||
== Special URLs == | |||
= Special URLs = | |||
You can request any file directly by specifying its exact path starting with $FW_dir, but there are also some special URLs available: | You can request any file directly by specifying its exact path starting with $FW_dir, but there are also some special URLs available: | ||
== Icons == | === Icons === | ||
<code><nowiki>http://hostname:port/<webname>/icons/<device></nowiki></code> | |||
This is the standard mechanism to get an icon representing a device. | This is the standard mechanism to get an icon representing a device. | ||
For finding an icon for a device, the directories are scanned by the iconPath FHEMWEB attribute, default ist stylesheetDir:fhemSVG:openautomation:default. Then the icon is chosen depending on the device name,type and state. The user can specify a devStateIcon to change this behaviour, and the module can also override it by specifying its FW_summaryFn | For finding an icon for a device, the directories are scanned by the iconPath FHEMWEB attribute, default ist stylesheetDir:fhemSVG:openautomation:default. Then the icon is chosen depending on the device name, type, and state. The user can specify a devStateIcon to change this behaviour, and the module can also override it by specifying its FW_summaryFn (see below for details). | ||
Due to historic reasons, you can still load any image from the iconPath directly by specifying its name without extension, but this feature may go away in the future. | Due to historic reasons, you can still load any image from the iconPath directly by specifying its name without extension, but this feature may go away in the future. | ||
== Documentation == | === Documentation === | ||
<code><nowiki>http://hostname:port/ http://hostname:port/<webname>/docs/file</nowiki></code> | |||
This is the standard mechanism to retrieve documentation, especially commandref.html: | This is the standard mechanism to retrieve documentation, especially commandref.html: | ||
:<code><nowiki>http://hostname:port/<webname>/docs/commandref.html</nowiki></code> | |||
== Usage in your own code == | === Usage in your own code === | ||
If you need an icon to be visualized in a web site, use the function FW_makeImage(<icon>). It returns the img tag for the icon plus a comment where the icon is located. It even | If you need an icon to be visualized in a web site, use the function FW_makeImage(<icon>). It returns the img tag for the icon plus a comment where the icon is located. It even returns an error message if no icon file exists that fits the requested logical name. | ||
Other useful functions are FW_iconPath(<icon>) to determine the full(!) path to the icon, e.g. $FW_icondir/dark/lamp.off.png. and FW_IconURL(<icon>) to determine the URL of the icon, e.g. | Other useful functions are FW_iconPath(<icon>) to determine the full(!) path to the icon, e.g. $FW_icondir/dark/lamp.off.png. and FW_IconURL(<icon>) to determine the URL of the icon, e.g. <code><nowiki>http://hostname:port/<webname>/icons/lamp.off</nowiki></code>. | ||
= Plugins = | == Plugins == | ||
FHEMWEB provides some meachnisms to plug-in own functionality. To do so, own routines can be registered in the hashes $data or $hash respectively, see details below. | FHEMWEB provides some meachnisms to plug-in own functionality. To do so, own routines can be registered in the hashes $data or $hash respectively, see details below. | ||
== FW_detailFn == | |||
Provides the possibility to display additional data on the details-screen of a device, will be | === FW_detailFn === | ||
Provides the possibility to display additional data on the details-screen of a device, will be displayed preceding the "Internals"-section. | |||
Registration in a modules' initialize-Routine: | Registration in a modules' initialize-Routine: | ||
:<code>$hash->{FW_detailFn} = "my_Routine";</code> | |||
my_Routine will be called with the parameters $FW_wname, $deviceName, $FW_room. Have a look at 01_FHEMWEB.pm for examples. | my_Routine will be called with the parameters $FW_wname, $deviceName, $FW_room. Have a look at 01_FHEMWEB.pm for examples. | ||
== FW_summaryFn== | |||
=== FW_summaryFn=== | |||
Provides the possibility to display own data instead of the state-icon of a device. | Provides the possibility to display own data instead of the state-icon of a device. | ||
Registration in a modules' initialize-Routine: | Registration in a modules' initialize-Routine: | ||
:<code>$hash->{FW_summaryFn} = "my_Routine";</code> | |||
my_Routine will be called with the parameters $FW_wname, $deviceName, $FW_room. Have a look at 01_FHEMWEB.pm for examples. | my_Routine will be called with the parameters $FW_wname, $deviceName, $FW_room. Have a look at 01_FHEMWEB.pm for examples. | ||
The return-value of my_routine can | The return-value of my_routine can be any of | ||
* html-code, checked by regexp <.*> | * html-code, checked by regexp <.*> | ||
* empty (""), will display the state as a text link | * empty (""), will display the state as a plain text link | ||
* undef, will continue the default search mechanism for a matching icon for STATE | * undef, will continue the default search mechanism for a matching icon for STATE | ||
== webCmdFn == | === webCmdFn === | ||
Provides the possibility to display own data instead of the command-list of a device. | Provides the possibility to display own data instead of the command-list of a device. | ||
Registration in a modules' initialize-Routine: | Registration in a modules' initialize-Routine: | ||
:<code>$data{webCmdFn}{myModule} = "my_Routine"; </code> | |||
my_Routine will be called with parameters $FW_wname, $deviceName, $FW_room, $cmd, $values. | my_Routine will be called with parameters $FW_wname, $deviceName, $FW_room, $cmd, $values. | ||
For more details refer to | For more details refer to {{Link2Forum|Topic=12460|LinkText=original thread in fhem-forum}}. | ||
[[Kategorie:Development]] | [[Kategorie:Development]] |
Version vom 16. Februar 2015, 13:54 Uhr
This page describes the FHEMWEB module from a developer's perspective.
Global Variables
The following global variables are used throughout FHEMWEB, and should be used if you are extending it:
- $FW_ME
- When using FHEMWEB, you have to specify a base path in all requests; this value is stored in the variable $FW_ME and defaults to /fhem. The user may change it by setting the webname attribute.
- $FW_dir
- base directory from which FHEMWEB serves files. Defaults to $attr{global}{modpath}/www.
- $FW_icondir
- base directory from which FHEMWEB serves icons. Defaults to $FW_dir/images.
- $FW_cssdir
- base directory from which FHEMWEB serves HTML and SVG style sheets and javascript files. Defaults to $FW_dir/pgm2.
- $FW_gplotdir
- base directory where FHEMWEB searches for gplot files. Defaults to $FW_dir/gplot.
Special URLs
You can request any file directly by specifying its exact path starting with $FW_dir, but there are also some special URLs available:
Icons
http://hostname:port/<webname>/icons/<device>
This is the standard mechanism to get an icon representing a device.
For finding an icon for a device, the directories are scanned by the iconPath FHEMWEB attribute, default ist stylesheetDir:fhemSVG:openautomation:default. Then the icon is chosen depending on the device name, type, and state. The user can specify a devStateIcon to change this behaviour, and the module can also override it by specifying its FW_summaryFn (see below for details).
Due to historic reasons, you can still load any image from the iconPath directly by specifying its name without extension, but this feature may go away in the future.
Documentation
http://hostname:port/ http://hostname:port/<webname>/docs/file
This is the standard mechanism to retrieve documentation, especially commandref.html:
http://hostname:port/<webname>/docs/commandref.html
Usage in your own code
If you need an icon to be visualized in a web site, use the function FW_makeImage(<icon>). It returns the img tag for the icon plus a comment where the icon is located. It even returns an error message if no icon file exists that fits the requested logical name.
Other useful functions are FW_iconPath(<icon>) to determine the full(!) path to the icon, e.g. $FW_icondir/dark/lamp.off.png. and FW_IconURL(<icon>) to determine the URL of the icon, e.g. http://hostname:port/<webname>/icons/lamp.off
.
Plugins
FHEMWEB provides some meachnisms to plug-in own functionality. To do so, own routines can be registered in the hashes $data or $hash respectively, see details below.
FW_detailFn
Provides the possibility to display additional data on the details-screen of a device, will be displayed preceding the "Internals"-section. Registration in a modules' initialize-Routine:
$hash->{FW_detailFn} = "my_Routine";
my_Routine will be called with the parameters $FW_wname, $deviceName, $FW_room. Have a look at 01_FHEMWEB.pm for examples.
FW_summaryFn
Provides the possibility to display own data instead of the state-icon of a device. Registration in a modules' initialize-Routine:
$hash->{FW_summaryFn} = "my_Routine";
my_Routine will be called with the parameters $FW_wname, $deviceName, $FW_room. Have a look at 01_FHEMWEB.pm for examples. The return-value of my_routine can be any of
- html-code, checked by regexp <.*>
- empty (""), will display the state as a plain text link
- undef, will continue the default search mechanism for a matching icon for STATE
webCmdFn
Provides the possibility to display own data instead of the command-list of a device. Registration in a modules' initialize-Routine:
$data{webCmdFn}{myModule} = "my_Routine";
my_Routine will be called with parameters $FW_wname, $deviceName, $FW_room, $cmd, $values.
For more details refer to original thread in fhem-forum.