mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
AndroidDB: Added creation of readings for shell commands
git-svn-id: https://svn.fhem.de/fhem/trunk@25879 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
3d13bc5006
commit
edfc3ce967
@ -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.
|
||||||
|
- feature: 89_AndroidDB: Added creation of readings for shell commands
|
||||||
- feature: 98_archetype: new option for FILTER in actual_.* attributes
|
- feature: 98_archetype: new option for FILTER in actual_.* attributes
|
||||||
- change: 98_archetype: now packaged, extend commandref
|
- change: 98_archetype: now packaged, extend commandref
|
||||||
- feature: 89_AndroidDB: Added FHEM reading attributes
|
- feature: 89_AndroidDB: Added FHEM reading attributes
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# 89_AndroidDB
|
# 89_AndroidDB
|
||||||
#
|
#
|
||||||
# Version 0.7
|
# Version 0.8
|
||||||
#
|
#
|
||||||
# FHEM Integration for Android Devices
|
# FHEM Integration for Android Devices
|
||||||
#
|
#
|
||||||
@ -37,7 +37,7 @@ sub AndroidDB_Initialize ($)
|
|||||||
$hash->{ShutdownFn} = "AndroidDB::Shutdown";
|
$hash->{ShutdownFn} = "AndroidDB::Shutdown";
|
||||||
|
|
||||||
$hash->{parseParams} = 1;
|
$hash->{parseParams} = 1;
|
||||||
$hash->{AttrList} = 'connect:0,1 macros:textField-long preset presetFile '.$readingFnAttributes;
|
$hash->{AttrList} = 'connect:0,1 createReadings macros:textField-long preset presetFile '.$readingFnAttributes;
|
||||||
|
|
||||||
$data{RC_layout}{MagentaTVStick} = "AndroidDB::RCLayoutMagentaTVStick";
|
$data{RC_layout}{MagentaTVStick} = "AndroidDB::RCLayoutMagentaTVStick";
|
||||||
$data{RC_layout}{MagentaOne} = "AndroidDB::RCLayoutMagentaOne";
|
$data{RC_layout}{MagentaOne} = "AndroidDB::RCLayoutMagentaOne";
|
||||||
@ -59,6 +59,7 @@ BEGIN {
|
|||||||
readingsBulkUpdateIfChanged
|
readingsBulkUpdateIfChanged
|
||||||
readingsBeginUpdate
|
readingsBeginUpdate
|
||||||
readingsEndUpdate
|
readingsEndUpdate
|
||||||
|
makeReadingName
|
||||||
setDevAttrList
|
setDevAttrList
|
||||||
CommandDefine
|
CommandDefine
|
||||||
CommandSet
|
CommandSet
|
||||||
@ -276,7 +277,10 @@ sub Set ($@)
|
|||||||
elsif ($lcopt eq 'shell') {
|
elsif ($lcopt eq 'shell') {
|
||||||
return "Usage: set $name $opt ShellCommand" if (scalar(@$a) == 0);
|
return "Usage: set $name $opt ShellCommand" if (scalar(@$a) == 0);
|
||||||
my ($rc, $result, $error) = AndroidDBHost::Run ($hash, $opt, '.*', @$a);
|
my ($rc, $result, $error) = AndroidDBHost::Run ($hash, $opt, '.*', @$a);
|
||||||
return $result.$error,
|
return $error if ($rc == 0);
|
||||||
|
my $createReadings = AttrVal ($name, 'createReadings', '');
|
||||||
|
return $result if ($createReadings eq '' || $createReadings !~ /$createReadings/);
|
||||||
|
UpdateReadings ($hash, $result);
|
||||||
}
|
}
|
||||||
elsif ($lcopt eq 'remotecontrol') {
|
elsif ($lcopt eq 'remotecontrol') {
|
||||||
my $macroName = shift @$a // return "Usage: set $name $opt MacroName";
|
my $macroName = shift @$a // return "Usage: set $name $opt MacroName";
|
||||||
@ -390,8 +394,10 @@ sub Attr ($@)
|
|||||||
|
|
||||||
if ($cmd eq 'set') {
|
if ($cmd eq 'set') {
|
||||||
if ($attrName eq 'macros') {
|
if ($attrName eq 'macros') {
|
||||||
|
delete $hash->{adb}{preset}{_custom_} if (exists($hash->{adb}{preset}{_custom_}));
|
||||||
|
delete $hash->{adb}{macro}{_custom_} if (exists($hash->{adb}{macro}{_custom_}));
|
||||||
foreach my $macroDef (split /;/, $attrVal) {
|
foreach my $macroDef (split /;/, $attrVal) {
|
||||||
my ($macroName, $macroPar) = split (':', $macroDef);
|
my ($macroName, $macroPar) = split (':', $macroDef, 2);
|
||||||
if (!defined($macroDef)) {
|
if (!defined($macroDef)) {
|
||||||
Log3 $name, 2, "Missing defintion for macro $macroName";
|
Log3 $name, 2, "Missing defintion for macro $macroName";
|
||||||
return "Missing definition for macro $macroName";
|
return "Missing definition for macro $macroName";
|
||||||
@ -415,6 +421,7 @@ sub Attr ($@)
|
|||||||
}
|
}
|
||||||
elsif ($cmd eq 'del') {
|
elsif ($cmd eq 'del') {
|
||||||
delete $hash->{adb}{preset}{_custom_} if (exists($hash->{adb}{preset}{_custom_}));
|
delete $hash->{adb}{preset}{_custom_} if (exists($hash->{adb}{preset}{_custom_}));
|
||||||
|
delete $hash->{adb}{macro}{_custom_} if (exists($hash->{adb}{macro}{_custom_}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@ -459,7 +466,7 @@ sub LoadPresets ($$)
|
|||||||
foreach my $l (@lines) {
|
foreach my $l (@lines) {
|
||||||
next if ($l =~ /^#/); # Comments are allowed
|
next if ($l =~ /^#/); # Comments are allowed
|
||||||
|
|
||||||
my ($macroName, $macroPar) = split (':', $l);
|
my ($macroName, $macroPar) = split (':', $l, 2);
|
||||||
if (!defined($macroPar)) {
|
if (!defined($macroPar)) {
|
||||||
next if (!defined($macroName) || $macroName eq '');
|
next if (!defined($macroName) || $macroName eq '');
|
||||||
if ($macroName !~ /^[a-zA-Z0-9-_]+$/) {
|
if ($macroName !~ /^[a-zA-Z0-9-_]+$/) {
|
||||||
@ -519,6 +526,24 @@ sub ExportPresets ($$)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub UpdateReadings ($$)
|
||||||
|
{
|
||||||
|
my ($hash, $data) = @_;
|
||||||
|
|
||||||
|
readingsBeginUpdate ($hash);
|
||||||
|
|
||||||
|
foreach my $line (split /[\n\r]+/, $data) {
|
||||||
|
$line =~ s/^\s+//; # Remove leading whitespace characters
|
||||||
|
next if ($line eq ''); # Ignore empty lines
|
||||||
|
my @a = split('=', $line);
|
||||||
|
next if (scalar(@a) != 2);
|
||||||
|
my $r = makeReadingName ($a[0]);
|
||||||
|
readingsBulkUpdate ($hash, $r, $a[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
readingsEndUpdate ($hash, 1);
|
||||||
|
}
|
||||||
|
|
||||||
sub ShowMessage ($$$)
|
sub ShowMessage ($$$)
|
||||||
{
|
{
|
||||||
my ($hash, $level, $msg) = @_;
|
my ($hash, $level, $msg) = @_;
|
||||||
@ -695,6 +720,11 @@ sub RCLayoutMagentaTVExt () {
|
|||||||
<li><b>connect 0|1</b><br/>
|
<li><b>connect 0|1</b><br/>
|
||||||
If set to 1, a connection to the Android device will be established during
|
If set to 1, a connection to the Android device will be established during
|
||||||
FHEM start. Note: Set this attribute for one Android device only!
|
FHEM start. Note: Set this attribute for one Android device only!
|
||||||
|
</li><br/>
|
||||||
|
<a name="createReadings"></a>
|
||||||
|
<li><b>createReadings <command-expression></b><br/>
|
||||||
|
Create readings for shell <i>command-expression</i>. Output must contain lines in format key=value.<br/>
|
||||||
|
Example: attr myDev createReadings dumpsys
|
||||||
</li><br/>
|
</li><br/>
|
||||||
<a name="macros"></a>
|
<a name="macros"></a>
|
||||||
<li><b>macros <MacroDef>[;...]</b><br/>
|
<li><b>macros <MacroDef>[;...]</b><br/>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# 89_AndroidDBHost
|
# 89_AndroidDBHost
|
||||||
#
|
#
|
||||||
# Version 0.7
|
# Version 0.8
|
||||||
#
|
#
|
||||||
# FHEM Integration for Android Debug Bridge
|
# FHEM Integration for Android Debug Bridge
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user