mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
98_exportdevice.pm: new command exportdevice (Forum #56911)
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@12044 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
db4104be04
commit
441e09e72a
1
CHANGED
1
CHANGED
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# 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)
|
- feature: 90_at: computeAfterInit attribute (Forum #56706)
|
||||||
- change: 93_DbRep: fit to new commandref style
|
- change: 93_DbRep: fit to new commandref style
|
||||||
- bugfix: 20_ROOMMATE,20_GUEST: Fixed wakeuptimer <> at-device sync
|
- bugfix: 20_ROOMMATE,20_GUEST: Fixed wakeuptimer <> at-device sync
|
||||||
|
193
FHEM/98_exportdevice.pm
Executable file
193
FHEM/98_exportdevice.pm
Executable 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ä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
|
||||||
|
<devspec>.
|
||||||
|
<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ätes aus. Dies
|
||||||
|
ist eines der wenigen Befehle, die im Normalfall eine Zeichenkette ausgeben.<br>
|
||||||
|
Siehe den Abschnitt über <a href="#devspec">Geräte-Spezifikation</a>
|
||||||
|
für Details der <devspec>.
|
||||||
|
<br><br>
|
||||||
|
Die Ausgabe kann fü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
|
3
HISTORY
3
HISTORY
@ -685,3 +685,6 @@
|
|||||||
|
|
||||||
- Sun Aug 21 2016 (mike3436)
|
- Sun Aug 21 2016 (mike3436)
|
||||||
- added new module 26_KM273 for buderus logatherm heat pump
|
- added new module 26_KM273 for buderus logatherm heat pump
|
||||||
|
|
||||||
|
- Mon Aug 22 2016 (loredo)
|
||||||
|
- added new command exportdevice
|
||||||
|
@ -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_OWTEMP.pm mfr69bs http://forum.fhem.de 1Wire (deprecated)
|
||||||
FHEM/21_OWTHERM.pm pahenning/ntruchsess http://forum.fhem.de 1Wire
|
FHEM/21_OWTHERM.pm pahenning/ntruchsess http://forum.fhem.de 1Wire
|
||||||
FHEM/21_SONOSPLAYER Reinerlein http://forum.fhem.de Multimedia
|
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_ALL4027.pm sachag http://forum.fhem.de Sonstiges
|
||||||
FHEM/23_KOSTALPIKO.pm john http://forum.fhem.de CodeSchnipsel
|
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)
|
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_CustomReadings.pm HCS http://forum.fhem.de Unterstuetzende Dienste
|
||||||
FHEM/98_dewpoint.pm Joachim http://forum.fhem.de Automatisierung
|
FHEM/98_dewpoint.pm Joachim http://forum.fhem.de Automatisierung
|
||||||
FHEM/98_dummy.pm rudolfkoenig 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_fheminfo.pm mfr69bs http://forum.fhem.de Sonstiges
|
||||||
FHEM/98_help.pm betateilchen 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
|
FHEM/98_HourCounter.pm john http://forum.fhem.de MAX
|
||||||
|
Loading…
x
Reference in New Issue
Block a user