initial
This commit is contained in:
commit
7cf35de7a3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.DS_Store
|
216
FHEM/73_HailoLibero.pm
Normal file
216
FHEM/73_HailoLibero.pm
Normal file
@ -0,0 +1,216 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Developed with love
|
||||
#
|
||||
# (c) 2021-2021 Copyright: Sebastian Schwarz
|
||||
#
|
||||
# This script 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 2 of the License, or
|
||||
# any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script 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.
|
||||
#
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
|
||||
package FHEM::HailoLibero;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use GPUtils qw(GP_Import GP_Export);
|
||||
require FHEM::Hailo::Libero;
|
||||
|
||||
|
||||
## Import der FHEM Funktionen
|
||||
#-- Run before package compilation
|
||||
BEGIN {
|
||||
|
||||
# Import from main context
|
||||
GP_Import(
|
||||
qw(
|
||||
readingFnAttributes
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#-- Export to main context with different name
|
||||
GP_Export(
|
||||
qw(
|
||||
Initialize
|
||||
)
|
||||
);
|
||||
|
||||
sub Initialize {
|
||||
my $hash = shift;
|
||||
|
||||
# Provider
|
||||
$hash->{WriteFn} = \&Write;
|
||||
|
||||
# Consumer
|
||||
$hash->{SetFn} = 'FHEM::Hailo::Libero::Set';
|
||||
$hash->{DefFn} = 'FHEM::Hailo::Libero::Define';
|
||||
$hash->{UndefFn} = 'FHEM::Hailo::Libero::Undef';
|
||||
$hash->{DeleteFn} = 'FHEM::Hailo::Libero::Delete';
|
||||
$hash->{RenameFn} = 'FHEM::Hailo::Libero::Rename';
|
||||
|
||||
$hash->{AttrFn} = 'FHEM::Hailo::Libero::Attr';
|
||||
$hash->{AttrList} =
|
||||
'debugJSON:0,1 '
|
||||
. 'disable:1 '
|
||||
. $readingFnAttributes;
|
||||
$hash->{parseParams} = 1;
|
||||
|
||||
return FHEM::Meta::InitMod( __FILE__, $hash );
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=item device
|
||||
=item summary Modul to communicate with the GardenaCloud
|
||||
=item summary_DE Modul zur Datenübertragung zur GardenaCloud
|
||||
|
||||
=begin html
|
||||
|
||||
<a name="HailoLibero"></a>
|
||||
<h3>HailoLibero</h3>
|
||||
<ul>
|
||||
<u><b>Prerequisite</b></u>
|
||||
<br><br>
|
||||
<li>coming soon</li>
|
||||
</ul>
|
||||
<br>
|
||||
<a name="HailoLiberodefine"></a>
|
||||
<b>Define</b>
|
||||
<ul><br>
|
||||
<code>define <name> HailoLibero</code>
|
||||
<br><br>
|
||||
Beispiel:
|
||||
<ul><br>
|
||||
<code>define Hailo_Libero HailoLibero</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
foo bar smaple tett
|
||||
<br><br>
|
||||
<a name="HailoLiberoreadings"></a>
|
||||
<br><br>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>foo - bar</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HailoLiberoeset"></a>
|
||||
<b>set</b>
|
||||
<ul>
|
||||
<li>foo - bar</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HailoLiberoeattributes"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>foo - barr2</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=begin html_DE
|
||||
|
||||
<a name="HailoLibero"></a>
|
||||
<h3>HailoLibero</h3>
|
||||
<ul>
|
||||
<u><b>Voraussetzungen</b></u>
|
||||
<br><br>
|
||||
<li>muss ich noch gucken</li>
|
||||
</ul>
|
||||
<br>
|
||||
<a name="HailoLiberodefine"></a>
|
||||
<b>Define</b>
|
||||
<ul><br>
|
||||
<code>define <name> HailoLibero</code>
|
||||
<br><br>
|
||||
Beispiel:
|
||||
<ul><br>
|
||||
<code>define Hailo_Libero HailoLibero</code><br>
|
||||
</ul>
|
||||
<br>
|
||||
Sample foo bar text
|
||||
<br><br>
|
||||
<a name="HailoLiberoreadings"></a>
|
||||
<br><br>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>foo - bar</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="HailoLiberoset"></a>
|
||||
<b>set</b>
|
||||
<ul>
|
||||
<li>foo - foo bar</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html_DE
|
||||
|
||||
=for :application/json;q=META.json 73_HeiloLibero.pm
|
||||
{
|
||||
"abstract": "Modul to control Hailo Libero 3.0",
|
||||
"x_lang": {
|
||||
"de": {
|
||||
"abstract": "Modul zum bedienen des Hailo Libero 3.0"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"fhem-mod-device",
|
||||
"fhem-core",
|
||||
"Hailo",
|
||||
"Libero",
|
||||
"Smart"
|
||||
],
|
||||
"release_status": "stable",
|
||||
"license": "GPL_2",
|
||||
"version": "v1.0.0",
|
||||
"author": [
|
||||
"Sebastian Schwarz <ema@il.local>"
|
||||
],
|
||||
"x_fhem_maintainer": [
|
||||
"CoolTux"
|
||||
],
|
||||
"x_fhem_maintainer_github": [
|
||||
"LeonGaultier"
|
||||
],
|
||||
"prereqs": {
|
||||
"runtime": {
|
||||
"requires": {
|
||||
"FHEM": 5.00918799,
|
||||
"perl": 5.016,
|
||||
"Meta": 0,
|
||||
"HttpUtils": 0,
|
||||
"Encode": 0
|
||||
},
|
||||
"recommends": {
|
||||
},
|
||||
"suggests": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
=end :application/json;q=META.json
|
||||
|
||||
=cut
|
40
hooks/pre-commit
Normal file
40
hooks/pre-commit
Normal file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use File::Basename;
|
||||
use POSIX qw(strftime);
|
||||
use strict;
|
||||
|
||||
my @filenames = (
|
||||
'FHEM/73_GardenaSmartBridge2.pm',
|
||||
'lib/FHEM/Gardena/SmartBridge.pm',
|
||||
);
|
||||
|
||||
my $controlsfile = 'controls_GardenaSmart.txt';
|
||||
|
||||
open(FH, ">$controlsfile") || return("Can't open $controlsfile: $!");
|
||||
|
||||
for my $filename (@filenames) {
|
||||
my @statOutput = stat($filename);
|
||||
|
||||
if (scalar @statOutput != 13) {
|
||||
printf 'error: stat has unexpected return value for ' . $filename . "\n";
|
||||
next;
|
||||
}
|
||||
|
||||
my $mtime = $statOutput[9];
|
||||
my $date = POSIX::strftime("%Y-%m-%d", localtime($mtime));
|
||||
my $time = POSIX::strftime("%H:%M:%S", localtime($mtime));
|
||||
my $filetime = $date."_".$time;
|
||||
|
||||
my $filesize = $statOutput[7];
|
||||
|
||||
printf FH 'UPD ' . $filetime . ' ' . $filesize . ' ' .$filename . "\n";
|
||||
}
|
||||
|
||||
close(FH);
|
||||
|
||||
system("git add $controlsfile");
|
||||
|
||||
print 'Create controls File succesfully' . "\n";
|
||||
|
||||
exit 0;
|
267
lib/FHEM/Hailo/Libero.pm
Normal file
267
lib/FHEM/Hailo/Libero.pm
Normal file
@ -0,0 +1,267 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Developed with love
|
||||
#
|
||||
# (c) 2021-2021 Copyright: Sebastian Schwarz
|
||||
#
|
||||
# This script 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 2 of the License, or
|
||||
# any later version.
|
||||
#
|
||||
# The GNU General Public License can be found at
|
||||
# http://www.gnu.org/copyleft/gpl.html.
|
||||
# A copy is found in the textfile GPL.txt and important notices to the license
|
||||
# from the author is found in LICENSE.txt distributed with these scripts.
|
||||
#
|
||||
# This script 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.
|
||||
#
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
package FHEM::Hailo::Libero;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
#use POSIX;
|
||||
|
||||
use FHEM::Meta;
|
||||
use GPUtils qw(GP_Import);
|
||||
use HttpUtils;
|
||||
use FHEM::Core::Password::Utils qw(:ALL);
|
||||
|
||||
|
||||
my $missingModul = '';
|
||||
|
||||
## Import der FHEM Funktionen
|
||||
#-- Run before package compilation
|
||||
BEGIN {
|
||||
|
||||
# Import from main context
|
||||
GP_Import(
|
||||
qw(readingsSingleUpdate
|
||||
readingsBulkUpdate
|
||||
readingsBulkUpdateIfChanged
|
||||
readingsBeginUpdate
|
||||
readingsEndUpdate
|
||||
Log3
|
||||
CommandAttr
|
||||
AttrVal
|
||||
ReadingsVal
|
||||
CommandDefMod
|
||||
modules
|
||||
setKeyValue
|
||||
getKeyValue
|
||||
getUniqueId
|
||||
RemoveInternalTimer
|
||||
InternalTimer
|
||||
defs
|
||||
init_done
|
||||
IsDisabled
|
||||
deviceEvents
|
||||
HttpUtils_NonblockingGet
|
||||
gettimeofday
|
||||
Dispatch)
|
||||
);
|
||||
}
|
||||
|
||||
sub Define {
|
||||
my $hash = shift // return;
|
||||
my $aArg = shift // return;
|
||||
|
||||
return $@ unless ( FHEM::Meta::SetInternals($hash) );
|
||||
use version 0.60; our $VERSION = FHEM::Meta::Get( $hash, 'version' );
|
||||
|
||||
return q{too few parameters: define <NAME> HailoLibero}
|
||||
if ( scalar( @{$aArg} ) != 2 );
|
||||
|
||||
my $name = shift @$aArg;
|
||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||
|
||||
CommandAttr( undef, $name . ' room Haeilo' )
|
||||
if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'initialized', 1 );
|
||||
|
||||
Log3($name, 3, qq{HailoLibero ($name) - defined HailoLibero});
|
||||
|
||||
### create password object to handle pass keystore
|
||||
$hash->{helper}->{passObj} = FHEM::Core::Password::Utils->new();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Undef {
|
||||
my $hash = shift;
|
||||
my $name = shift;
|
||||
|
||||
$hash->{helper}->{passObj}->setDeletePassword($name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Attr {
|
||||
my ( $cmd, $name, $attrName, $attrVal ) = @_;
|
||||
my $hash = $defs{$name};
|
||||
|
||||
if ( $attrName eq 'disable' ) {
|
||||
if ( $cmd eq 'set' && $attrVal eq '1' ) {
|
||||
RemoveInternalTimer($hash);
|
||||
readingsSingleUpdate( $hash, 'state', 'inactive', 1 );
|
||||
Log3($name, 3, qq{HailoLibero ($name) - disabled});
|
||||
}
|
||||
elsif ( $cmd eq 'del' ) {
|
||||
readingsSingleUpdate( $hash, 'state', 'active', 1 );
|
||||
Log3($name, 3, qq{HailoLibero ($name) - enabled});
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub Set {
|
||||
my $hash = shift // return;
|
||||
my $aArg = shift // return;
|
||||
|
||||
my $name = shift @$aArg // return;
|
||||
my $cmd = shift @$aArg // return qq{"set $name" needs at least one argument};
|
||||
|
||||
# Das Argument für das Passwort, also das Passwort an sich darf keine = enthalten!!!
|
||||
|
||||
|
||||
if ( lc $cmd eq 'hailopwd' ) {
|
||||
|
||||
my ($passResp,$passErr);
|
||||
($passResp,$passErr) = $hash->{helper}->{passObj}->setStorePassword($name,$aArg->[0]);
|
||||
|
||||
return qq{error while saving the password - $passErr}
|
||||
if ( !defined($passResp)
|
||||
and defined($passErr) );
|
||||
|
||||
return q{password successfully saved}
|
||||
if ( defined($passResp)
|
||||
and !defined($passErr) );
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
my $list = "hailopwd "
|
||||
return "Unknown argument $cmd, choose one of $list";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Delete {
|
||||
my $hash = shift;
|
||||
my $name = shift;
|
||||
|
||||
$hash->{helper}->{passObj}->setDeletePassword($name);
|
||||
return;
|
||||
}
|
||||
|
||||
sub Write {
|
||||
my ( $hash, $payload ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my ( $session_id, $header, $uri, $method );
|
||||
|
||||
( $payload, $session_id, $header, $uri, $method ) =
|
||||
createHttpValueStrings( $hash, $payload );
|
||||
|
||||
HttpUtils_NonblockingGet(
|
||||
{
|
||||
url => $hash->{URL} . $uri,
|
||||
timeout => 15,
|
||||
hash => $hash,
|
||||
data => $payload,
|
||||
method => $method,
|
||||
header => $header,
|
||||
doTrigger => 1,
|
||||
callback => \&ErrorHandling
|
||||
}
|
||||
);
|
||||
|
||||
Log3( $name, 4,
|
||||
"HailoLibero ($name) - Send with URL: $hash->{URL}$uri, HEADER: secret!, DATA: secret!, METHOD: $method"
|
||||
);
|
||||
|
||||
# Log3($name, 3,
|
||||
# "HailoLibero ($name) - Send with URL: $hash->{URL}$uri, HEADER: $header, DATA: $payload, METHOD: $method");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub ErrorHandling {
|
||||
my $param = shift;
|
||||
my $err = shift;
|
||||
my $data = shift;
|
||||
|
||||
my $hash = $param->{hash};
|
||||
my $name = $hash->{NAME};
|
||||
my $dhash = $hash;
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'Connected', 1 );
|
||||
ResponseProcessing( $hash, $data );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub ResponseProcessing {
|
||||
my $hash = shift;
|
||||
my $json = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Log3 $name, 3, "HailoLibero ($name) - no Match for processing data";
|
||||
return;
|
||||
}
|
||||
|
||||
sub WriteReadings {
|
||||
my $hash = shift;
|
||||
my $decode_json = shift;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Log3 $name, 4, "HailoLibero ($name) - readings would be written";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
####################################
|
||||
####################################
|
||||
#### my little helpers Sub's #######
|
||||
|
||||
s
|
||||
|
||||
sub Rename {
|
||||
my $new = shift;
|
||||
my $old = shift;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub createHttpValueStrings {
|
||||
my ( $hash, $payload ) = @_;
|
||||
|
||||
my $session_id = $hash->{helper}{session_id};
|
||||
my $header = "Content-Type: application/json";
|
||||
my $uri = '';
|
||||
my $method = 'POST';
|
||||
$payload = '{}' if ( !defined($payload) );
|
||||
$uri .= '?parms';
|
||||
|
||||
return ( $payload, $session_id, $header, $uri, $method );
|
||||
}
|
||||
|
||||
1;
|
Loading…
x
Reference in New Issue
Block a user