2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-15 22:26:04 +00:00

98_exportdevice.pm: new command exportdevice (Forum #56911)

git-svn-id: https://svn.fhem.de/fhem/trunk@12044 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2016-08-21 23:41:05 +00:00
parent 47a2e2dc49
commit 626dfbbefe
4 changed files with 199 additions and 1 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- added: 98_exportdevice: new command to export device definitions
- feature: 90_at: computeAfterInit attribute (Forum #56706)
- change: 93_DbRep: fit to new commandref style
- bugfix: 20_ROOMMATE,20_GUEST: Fixed wakeuptimer <> at-device sync

193
fhem/FHEM/98_exportdevice.pm Executable file
View File

@ -0,0 +1,193 @@
# $Id$
package main;
use strict;
use warnings;
sub CommandExportdevice($$);
########################################
sub exportdevice_Initialize($$) {
my %hash = (
Fn => "CommandExportdevice",
Hlp => "<device>",
);
$cmds{exportdevice} = \%hash;
}
########################################
sub CommandExportdevice($$) {
my ( $cl, $param ) = @_;
my @a = split( "[ \t][ \t]*", $param );
my $quote = 0;
my $str = "";
return "Usage: exportdevice [devspec] [quote]"
if ( $a[0] eq "?" );
$quote = 1
if ( $a[0] eq "quote" || $a[1] eq "quote" );
$a[0] = ".*"
if ( int(@a) < 1 || $a[0] eq "quote" );
my $mname = "";
foreach my $dev ( devspec2array( $a[0], $cl ) ) {
next if ( !$defs{$dev} );
# module header (only once)
if ( $mname ne $defs{$dev}{TYPE} ) {
$mname = $defs{$dev}{TYPE};
my $ver = fhem "version $defs{$dev}{TYPE}";
$ver =~ s/\n\n+/\n# /g;
$ver =~ s/^/# /g;
$str .= "\n\n# TYPE: $defs{$dev}{TYPE}\n$ver\n\n";
}
# device definition
if ( $dev ne "global" ) {
my $def = $defs{$dev}{DEF};
if ( defined($def) ) {
if ($quote) {
$def =~ s/;/;;/g;
$def =~ s/\n/\\\n/g;
}
$str .= "define $dev $defs{$dev}{TYPE} $def\n";
}
else {
$str .= "define $dev $defs{$dev}{TYPE}\n";
}
}
# device attributes
foreach my $a (
sort {
return -1
if ( $a eq "userattr" ); # userattr must be first
return 1 if ( $b eq "userattr" );
return $a cmp $b;
} keys %{ $attr{$dev} }
)
{
next
if ( $dev eq "global"
&& ( $a eq "configfile" || $a eq "version" ) );
my $val = $attr{$dev}{$a};
if ($quote) {
$val =~ s/;/;;/g;
$val =~ s/\n/\\\n/g;
}
$str .= "attr $dev $a $val\n";
}
$str .= "\n";
}
my $return;
$return = "#\n# Flat Export created by "
if ( !$quote );
$return = "#\n# Quoted Export created by "
if ($quote);
return
$return
. AttrVal( "global", "version", "fhem.pl:?/?" )
. "\n# on "
. TimeNow() . "\n#"
. $str
if ( $str ne "" );
return "No device found: $a[0]";
}
1;
=pod
=item command
=item summary exports definition and attributes of devices
=item summary_DE exportiert die Definition und die Attribute von Ger&auml;ten
=begin html
<a name="exportdevice"></a>
<h3>exportdevice</h3>
<ul>
<code>exportdevice [devspec] [quote]</code>
<br><br>
Output a complete device and attribute definition of FHEM devices. This is
one of the few commands which return a string in a normal case.<br>
See the <a href="#devspec">Device specification</a> section for details on
&lt;devspec&gt;.
<br><br>
The output can be used for reimport using FHEMWEB or telnet command line.<br>
The optional paramter "quote" may be added to receive fhem.cfg compatible output.
<br><br>
Example:
<pre><code> fhem> exportdevice Office
#
# Export created by fhem.pl:12022/2016-08-21
# on 2016-08-22 01:02:59
#
# TYPE: FS20
# File Rev Last Change
# 10_FS20.pm 11984 2016-08-19 12:47:50Z rudolfkoenig
define Office FS20 1234 12
attr Office userattr Light Light_map structexclude
attr Office IODev CUL_0
attr Office Light AllLights
attr Office group Single Lights
attr Office icon light_office
attr Office model fs20st
attr Office room Light
</code></pre>
</ul>
=end html
=begin html_DE
<a name="exportdevice"></a>
<h3>exportdevice</h3>
<ul>
<code>exportdevice [devspec] [quote]</code>
<br><br>
Gibt die komplette Definition und Attribute eines FHEM Ger&auml;tes aus. Dies
ist eines der wenigen Befehle, die im Normalfall eine Zeichenkette ausgeben.<br>
Siehe den Abschnitt &uuml;ber <a href="#devspec">Ger&auml;te-Spezifikation</a>
f&uuml;r Details der &lt;devspec&gt;.
<br><br>
Die Ausgabe kann f&uuml;r einen Reimport mittels FHEMWEB oder Telnet
Kommandozeile verwendet werden.<br>
Der optionale Parameter "quote" kann genutzt werden, um eine fhem.cfg
kompatible Ausgabe zu erhalten.
<br><br>
Beispiel:
<pre><code> fhem> exportdevice Office
#
# Export created by fhem.pl:12022/2016-08-21
# on 2016-08-22 01:02:59
#
# TYPE: FS20
# File Rev Last Change
# 10_FS20.pm 11984 2016-08-19 12:47:50Z rudolfkoenig
define Office FS20 1234 12
attr Office userattr Light Light_map structexclude
attr Office IODev CUL_0
attr Office Light AllLights
attr Office group Single Lights
attr Office icon light_office
attr Office model fs20st
attr Office room Light
</code></pre>
</ul>
=end html_DE
=cut

View File

@ -685,3 +685,6 @@
- Sun Aug 21 2016 (mike3436)
- added new module 26_KM273 for buderus logatherm heat pump
- Mon Aug 22 2016 (loredo)
- added new command exportdevice

View File

@ -112,7 +112,7 @@ FHEM/21_OWSWITCH.pm pahenning/ntruchsess http://forum.fhem.de 1Wire
FHEM/21_OWTEMP.pm mfr69bs http://forum.fhem.de 1Wire (deprecated)
FHEM/21_OWTHERM.pm pahenning/ntruchsess http://forum.fhem.de 1Wire
FHEM/21_SONOSPLAYER Reinerlein http://forum.fhem.de Multimedia
FHEM/22_ALL3076.pm sachag http://forum.fhem.de Snstiges
FHEM/22_ALL3076.pm sachag http://forum.fhem.de Sonstiges
FHEM/23_ALL4027.pm sachag http://forum.fhem.de Sonstiges
FHEM/23_KOSTALPIKO.pm john http://forum.fhem.de CodeSchnipsel
FHEM/23_LUXTRONIK2.pm tupol http://forum.fhem.de Sonstiges (link als PM an tupol)
@ -355,6 +355,7 @@ FHEM/98_count.pm betateilchen http://forum.fhem.de Sonstiges
FHEM/98_CustomReadings.pm HCS http://forum.fhem.de Unterstuetzende Dienste
FHEM/98_dewpoint.pm Joachim http://forum.fhem.de Automatisierung
FHEM/98_dummy.pm rudolfkoenig http://forum.fhem.de Automatisierung
FHEM/98_exportdevice.pm loredo http://forum.fhem.de Sonstiges
FHEM/98_fheminfo.pm mfr69bs http://forum.fhem.de Sonstiges
FHEM/98_help.pm betateilchen http://forum.fhem.de Sonstiges
FHEM/98_HourCounter.pm john http://forum.fhem.de MAX