fix up
This commit is contained in:
parent
0c53e0de2d
commit
358259fdc4
@ -24,7 +24,6 @@
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
|
||||
package FHEM::HailoLibero;
|
||||
|
||||
use strict;
|
||||
@ -33,11 +32,10 @@ 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(
|
||||
@ -65,25 +63,27 @@ sub Initialize {
|
||||
$hash->{UndefFn} = 'FHEM::Hailo::Libero::Undef';
|
||||
$hash->{DeleteFn} = 'FHEM::Hailo::Libero::Delete';
|
||||
$hash->{RenameFn} = 'FHEM::Hailo::Libero::Rename';
|
||||
$hash->{NotifyFn} = 'FHEM::Hailo::Libero::Notify';
|
||||
|
||||
|
||||
$hash->{AttrFn} = 'FHEM::Hailo::Libero::Attr';
|
||||
$hash->{AttrList} =
|
||||
'debugJSON:0,1 '
|
||||
. 'disable:1 '
|
||||
. 'LiberoIP '
|
||||
. $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
|
||||
=item summary Modul to communicate with the Hailo Libero
|
||||
=item summary_DE Modul zur Datenübertragung zur Hailo Libero
|
||||
|
||||
=begin html
|
||||
|
||||
@ -168,7 +168,7 @@ sub Initialize {
|
||||
|
||||
=end html_DE
|
||||
|
||||
=for :application/json;q=META.json 73_HeiloLibero.pm
|
||||
=for :application/json;q=META.json 73_HailoLibero.pm
|
||||
{
|
||||
"abstract": "Modul to control Hailo Libero 3.0",
|
||||
"x_lang": {
|
||||
@ -185,15 +185,15 @@ sub Initialize {
|
||||
],
|
||||
"release_status": "stable",
|
||||
"license": "GPL_2",
|
||||
"version": "v1.0.0",
|
||||
"version": "v1.1.0",
|
||||
"author": [
|
||||
"Sebastian Schwarz <ema@il.local>"
|
||||
],
|
||||
"x_fhem_maintainer": [
|
||||
"CoolTux"
|
||||
"BOFH"
|
||||
],
|
||||
"x_fhem_maintainer_github": [
|
||||
"LeonGaultier"
|
||||
"NO ONE"
|
||||
],
|
||||
"prereqs": {
|
||||
"runtime": {
|
||||
|
2
controls_HailoLibero.txt
Normal file
2
controls_HailoLibero.txt
Normal file
@ -0,0 +1,2 @@
|
||||
UPD 2021-05-25_20:13:57 4394 FHEM/73_HailoLibero.pm
|
||||
UPD 2021-05-24_22:53:00 10892 lib/FHEM/Hailo/Libero.pm
|
@ -5,11 +5,11 @@ use POSIX qw(strftime);
|
||||
use strict;
|
||||
|
||||
my @filenames = (
|
||||
'FHEM/73_GardenaSmartBridge2.pm',
|
||||
'lib/FHEM/Gardena/SmartBridge.pm',
|
||||
'FHEM/73_HailoLibero.pm',
|
||||
'lib/FHEM/Hailo/Libero.pm',
|
||||
);
|
||||
|
||||
my $controlsfile = 'controls_GardenaSmart.txt';
|
||||
my $controlsfile = 'controls_HailoLibero.txt';
|
||||
|
||||
open(FH, ">$controlsfile") || return("Can't open $controlsfile: $!");
|
||||
|
||||
|
@ -30,10 +30,13 @@ use strict;
|
||||
use warnings;
|
||||
#use POSIX;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
|
||||
use FHEM::Meta;
|
||||
use GPUtils qw(GP_Import);
|
||||
use HttpUtils;
|
||||
use FHEM::Core::Password::Utils qw(:ALL);
|
||||
use FHEM::Core::Authentication::Passwords qw(:ALL);
|
||||
|
||||
|
||||
my $missingModul = '';
|
||||
@ -81,17 +84,22 @@ sub Define {
|
||||
if ( scalar( @{$aArg} ) != 2 );
|
||||
|
||||
my $name = shift @$aArg;
|
||||
$hash->{URL} =
|
||||
AttrVal( $name, 'LiberoIP', 'http://192.168.0.1:81');
|
||||
|
||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||
|
||||
CommandAttr( undef, $name . ' room Haeilo' )
|
||||
CommandAttr( undef, $name . ' room Hailo' )
|
||||
if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'initialized', 1 );
|
||||
readingsSingleUpdate( $hash, 'cookie', 'none', 1 );
|
||||
|
||||
|
||||
Log3($name, 3, qq{HailoLibero ($name) - defined HailoLibero});
|
||||
|
||||
### create password object to handle pass keystore
|
||||
$hash->{helper}->{passObj} = FHEM::Core::Password::Utils->new();
|
||||
$hash->{helper}->{passObj} = FHEM::Core::Authentication::Passwords->new($hash->{TYPE});
|
||||
|
||||
return;
|
||||
}
|
||||
@ -120,11 +128,72 @@ sub Attr {
|
||||
Log3($name, 3, qq{HailoLibero ($name) - enabled});
|
||||
}
|
||||
}
|
||||
elsif ( $attrName eq 'LiberoIP') {
|
||||
if ( $cmd eq 'set' ) {
|
||||
$hash->{URL} = "http://$attrVal:81";
|
||||
Log3 $name, 3,
|
||||
"HailoLibero ($name) - set LiberoIP to: $attrVal";
|
||||
} elsif ( $cmd eq 'del' ) {
|
||||
$hash->{URL} = 'http://192.168.0.1:81';
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
sub Notify {
|
||||
my $hash = shift // return;
|
||||
my $dev = shift // return;
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
return if ( IsDisabled($name) );
|
||||
|
||||
my $devname = $dev->{NAME};
|
||||
my $devtype = $dev->{TYPE};
|
||||
my $events = deviceEvents( $dev, 1 );
|
||||
return if ( !$events );
|
||||
|
||||
getCookie($hash)
|
||||
if (
|
||||
(
|
||||
$devtype eq 'Global'
|
||||
&& (
|
||||
grep /^INITIALIZED$/,
|
||||
@{$events} or grep /^REREADCFG$/,
|
||||
@{$events} or grep /^DEFINED.$name$/,
|
||||
@{$events} or grep /^MODIFIED.$name$/,
|
||||
@{$events}
|
||||
)
|
||||
)
|
||||
|
||||
|| (
|
||||
$devtype eq 'HailoLibero'
|
||||
&& (
|
||||
grep /^LiberoIP.+/,
|
||||
@{$events}
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
if (
|
||||
$devtype eq 'HailoLibero'
|
||||
&& (
|
||||
grep /^cookie:.*$/,
|
||||
@{$events}
|
||||
)
|
||||
)
|
||||
{
|
||||
getSettings($hash);
|
||||
#InternalTimer( gettimeofday() + $hash->{INTERVAL},
|
||||
# "FHEM::GardenaSmartBridge::getDevices", $hash );
|
||||
Log3 $name, 4,
|
||||
"HailoLibero ($name) - set internal timer function for recall getSettings sub";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Set {
|
||||
my $hash = shift // return;
|
||||
@ -136,7 +205,7 @@ sub Set {
|
||||
# Das Argument für das Passwort, also das Passwort an sich darf keine = enthalten!!!
|
||||
|
||||
|
||||
if ( lc $cmd eq 'hailopwd' ) {
|
||||
if ( lc $cmd eq 'password' ) {
|
||||
|
||||
my ($passResp,$passErr);
|
||||
($passResp,$passErr) = $hash->{helper}->{passObj}->setStorePassword($name,$aArg->[0]);
|
||||
@ -148,11 +217,29 @@ sub Set {
|
||||
return q{password successfully saved}
|
||||
if ( defined($passResp)
|
||||
and !defined($passErr) );
|
||||
}
|
||||
|
||||
else {
|
||||
}
|
||||
elsif ( lc $cmd =~ /open|led_brightness|eject_power|eject_delay|detection_area|detection_sensitivity/ ) {
|
||||
return "please set Attribut LiberoIP first"
|
||||
if ( AttrVal( $name, 'LiberoIP', 'none' ) eq 'none' );
|
||||
Log3 $name, 1, "Poste an die Libero";
|
||||
|
||||
getCookie($hash)
|
||||
if (ReadingsVal( $name, 'cookie', 'none' ) eq 'none');
|
||||
|
||||
# sende befehl
|
||||
|
||||
# reade settings
|
||||
getSettings($hash)
|
||||
if(lc $cmd ne 'open');
|
||||
|
||||
}
|
||||
else {
|
||||
my $list = 'password ';
|
||||
$list .= 'open:noArg led_brightness:slider,1,1,10 eject_power:slider,1,1,10 eject_delay:slider,0,1,5 detection_area:31,1,100 detection_sensitivity:slider,1,1,50'
|
||||
if ( defined(ReadPassword( $hash, $name ))
|
||||
&& AttrVal( $name, 'LiberoIP', 'none' ) ne 'none'
|
||||
);
|
||||
|
||||
my $list = "hailopwd "
|
||||
return "Unknown argument $cmd, choose one of $list";
|
||||
}
|
||||
|
||||
@ -167,13 +254,33 @@ sub Delete {
|
||||
return;
|
||||
}
|
||||
|
||||
sub getCookie {
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
Log3 $name, 3, "HailoLibero ($name) - catch cookies";
|
||||
|
||||
Write (
|
||||
$hash,
|
||||
'pin='
|
||||
.ReadPassword($hash, $name)
|
||||
.'&submit='
|
||||
)
|
||||
}
|
||||
|
||||
sub getSettings {
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Write( $hash, undef, undef, undef );
|
||||
|
||||
}
|
||||
sub Write {
|
||||
my ( $hash, $payload ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my ( $session_id, $header, $uri, $method );
|
||||
my ( $header, $uri, $method );
|
||||
|
||||
( $payload, $session_id, $header, $uri, $method ) =
|
||||
( $payload, $header, $uri, $method ) =
|
||||
createHttpValueStrings( $hash, $payload );
|
||||
|
||||
HttpUtils_NonblockingGet(
|
||||
@ -184,17 +291,17 @@ sub Write {
|
||||
data => $payload,
|
||||
method => $method,
|
||||
header => $header,
|
||||
doTrigger => 1,
|
||||
ignoreredirects => 1,
|
||||
#doTrigger => 1,
|
||||
callback => \&ErrorHandling
|
||||
}
|
||||
);
|
||||
|
||||
Log3( $name, 4,
|
||||
"HailoLibero ($name) - Send with URL: $hash->{URL}$uri, HEADER: secret!, DATA: secret!, METHOD: $method"
|
||||
);
|
||||
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");
|
||||
Log3($name, 3,
|
||||
"HailoLibero ($name) - Send with URL: $hash->{URL}$uri, HEADER: $header, DATA: $payload, METHOD: $method");
|
||||
|
||||
return;
|
||||
}
|
||||
@ -208,20 +315,53 @@ sub ErrorHandling {
|
||||
my $name = $hash->{NAME};
|
||||
my $dhash = $hash;
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'Connected', 1 );
|
||||
ResponseProcessing( $hash, $data );
|
||||
|
||||
|
||||
if ( ReadingsVal( $name, 'cookie', 'none' ) eq 'none' ){
|
||||
my (@cookies) = ($param->{httpheader} =~ /Set-Cookie: (.*)\s/g);
|
||||
foreach my $cookie (@cookies){
|
||||
readingsSingleUpdate( $hash, 'state', 'connected', 1 );
|
||||
readingsSingleUpdate( $hash, 'cookie', $cookie, 1 );
|
||||
Log3 $name, 4, 'eat cookie: '.$cookie;
|
||||
}
|
||||
} else {
|
||||
# got cookie ... do something
|
||||
#ledo pwro disto delayo sldrlbl
|
||||
print $data;
|
||||
my ($led_brightness) = ($data =~ /led'>(\d*)/g);
|
||||
Log3 $name, 1, "Libero $name read led $led_brightness";
|
||||
my ($eject_power) = ($data =~ /pwr'>(\d*)/g);
|
||||
my ($detection_area) = ($data =~ /dist'>(\d*)/g);
|
||||
my ($detection_sensitivity) = ($data =~ /delay'>(\d*)/g);
|
||||
my ($eject_delay) = ($data =~ /pdelay'>(\d*)/g);
|
||||
readingsSingleUpdate($hash, 'led_brightness', $led_brightness, 1);
|
||||
readingsSingleUpdate($hash, 'eject_power', $eject_power, 1);
|
||||
readingsSingleUpdate($hash, 'detection_area', $detection_area, 1);
|
||||
readingsSingleUpdate($hash, 'detection_sensitivity', $detection_sensitivity, 1);
|
||||
readingsSingleUpdate($hash, 'eject_delay', $eject_delay, 1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub ResponseProcessing {
|
||||
my $hash = shift;
|
||||
my $json = shift;
|
||||
|
||||
sub createHttpValueStrings {
|
||||
my ( $hash, $payload ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Log3 $name, 3, "HailoLibero ($name) - no Match for processing data";
|
||||
return;
|
||||
my $header = "Content-Type: application/x-www-form-urlencoded";
|
||||
$header .= "\r\nCookie: ".ReadingsVal( $name, 'cookie', 'none' )
|
||||
if (ReadingsVal( $name, 'cookie', 'none' ) ne 'none');
|
||||
my $uri = '';
|
||||
my $method = 'POST';
|
||||
$payload = '{}' if ( !defined($payload) );
|
||||
|
||||
if ( ReadingsVal( $name, 'cookie', 'none' ) eq 'none' ){
|
||||
$uri .= '/login';
|
||||
readingsSingleUpdate( $hash, 'state', 'fetch cookie', 1 );
|
||||
} else {
|
||||
$uri .= '/admin';
|
||||
$method = 'GET';
|
||||
}
|
||||
return ( $payload, $header, $uri, $method );
|
||||
}
|
||||
|
||||
sub WriteReadings {
|
||||
@ -239,29 +379,34 @@ sub WriteReadings {
|
||||
####################################
|
||||
#### my little helpers Sub's #######
|
||||
|
||||
s
|
||||
sub ReadPassword {
|
||||
my $hash = shift;
|
||||
my $name = shift;
|
||||
|
||||
sub Rename {
|
||||
my $new = shift;
|
||||
my $old = shift;
|
||||
my $password;
|
||||
|
||||
Log3 $name, 4, "Hail ($name) - Read password from file";
|
||||
$password = $hash->{helper}->{passObj}->getReadPassword($name);
|
||||
|
||||
if ( defined($password) ) {
|
||||
return $password;
|
||||
} else {
|
||||
Log3 $name, 3, "Hail ($name) - No password in file";
|
||||
return undef;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Rename {
|
||||
my $new = shift;
|
||||
my $old = shift;
|
||||
|
||||
my $hash = $defs{$new};
|
||||
|
||||
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 );
|
||||
$hash->{helper}->{passObj}->getRename($new,$old);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user