initial push
This commit is contained in:
parent
7656674d54
commit
8532d3dafe
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.DS_Store
|
211
FHEM/73_GoECharger.pm
Normal file
211
FHEM/73_GoECharger.pm
Normal file
@ -0,0 +1,211 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Developed with love
|
||||
#
|
||||
# (c) 2022-2022 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::GoECharger;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use GPUtils qw(GP_Import GP_Export);
|
||||
require FHEM::Devices::GoE::GoECharger;
|
||||
|
||||
## 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::Devices::GoE::GoECharger::Set';
|
||||
$hash->{DefFn} = 'FHEM::Devices::GoE::GoECharger::Define';
|
||||
$hash->{UndefFn} = 'FHEM::Devices::GoE::GoECharger::Undef';
|
||||
$hash->{DeleteFn} = 'FHEM::Devices::GoE::GoECharger::Delete';
|
||||
$hash->{RenameFn} = 'FHEM::Devices::GoE::GoECharger::Rename';
|
||||
$hash->{NotifyFn} = 'FHEM::Devices::GoE::GoECharger::Notify';
|
||||
|
||||
|
||||
$hash->{AttrFn} = 'FHEM::Devices::GoE::GoECharger::Attr';
|
||||
$hash->{AttrList} =
|
||||
'disable:1 '
|
||||
. 'interval '
|
||||
. $readingFnAttributes;
|
||||
$hash->{parseParams} = 1;
|
||||
|
||||
return FHEM::Meta::InitMod( __FILE__, $hash );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
=pod
|
||||
|
||||
=item device
|
||||
=item summary Modul to control go e charger
|
||||
=item summary_DE Modul zur Steuerung eines go e charger
|
||||
|
||||
=begin html
|
||||
|
||||
<a name="GoECharger"></a>
|
||||
<h3>GoECharger</h3>
|
||||
<a name="GoEChargerdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul><br>
|
||||
<code>define <name> GoECharger </code>
|
||||
<br><br>
|
||||
Example:
|
||||
<ul><br>
|
||||
<code>define goe GoECharger </code><br>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="GoEChargerreadings"></a>
|
||||
<br><br>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>1st</li>
|
||||
<li>2nd</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="GoEChargereset"></a>
|
||||
<b>set</b>
|
||||
<ul>
|
||||
<li>first</li>
|
||||
<li>secibd</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="GoEChargereattributes"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>foo</li>
|
||||
<li>bar</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
=end html
|
||||
=begin html_DE
|
||||
|
||||
<a name="GoECharger"></a>
|
||||
<h3>GoECharger</h3>
|
||||
<br>
|
||||
<a name="GoEChargerdefine"></a>
|
||||
<b>Define</b>
|
||||
<ul><br>
|
||||
<code>define <name> GoECharger</code>
|
||||
<br><br>
|
||||
Beispiel:
|
||||
<ul><br>
|
||||
<code>define goe GoECharger</code><br>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="GoEChargerreadings"></a>
|
||||
<br><br>
|
||||
<b>Readings</b>
|
||||
<ul>
|
||||
<li>1st</li>
|
||||
<li>2nd</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="GoEChargerset"></a>
|
||||
<b>set</b>
|
||||
<ul>
|
||||
<li>erstens </li>
|
||||
<li>zweitens</li>
|
||||
</ul>
|
||||
<br><br>
|
||||
<a name="GoEChargereattributes"></a>
|
||||
<b>Attributes</b>
|
||||
<ul>
|
||||
<li>foo</li>
|
||||
<li>bar</li>
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
|
||||
=end html_DE
|
||||
|
||||
=for :application/json;q=META.json 73_GoECharger.pm
|
||||
{
|
||||
"abstract": "Modul to control go e charger",
|
||||
"x_lang": {
|
||||
"de": {
|
||||
"abstract": "Modul zum bedienen des go e charger"
|
||||
}
|
||||
},
|
||||
"keywords": [
|
||||
"fhem-mod-device",
|
||||
"fhem-core",
|
||||
"goe",
|
||||
"goecharger",
|
||||
"Smart"
|
||||
],
|
||||
"release_status": "stable",
|
||||
"license": "GPL_2",
|
||||
"version": "v0.0.1",
|
||||
"author": [
|
||||
"Sebastian Schwarz <ema@il.local>"
|
||||
],
|
||||
"x_fhem_maintainer": [
|
||||
"BOFH"
|
||||
],
|
||||
"x_fhem_maintainer_github": [
|
||||
"NO ONE"
|
||||
],
|
||||
"prereqs": {
|
||||
"runtime": {
|
||||
"requires": {
|
||||
"FHEM": 5.00918799,
|
||||
"perl": 5.016,
|
||||
"Meta": 0,
|
||||
"HttpUtils": 0,
|
||||
"Encode": 0
|
||||
},
|
||||
"recommends": {
|
||||
},
|
||||
"suggests": {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
=end :application/json;q=META.json
|
||||
|
||||
=cut
|
2
controls_GoECharger.txt
Normal file
2
controls_GoECharger.txt
Normal file
@ -0,0 +1,2 @@
|
||||
UPD 2022-05-28_16:25:11 4351 FHEM/73_GoECharger.pm
|
||||
UPD 2022-05-28_17:07:52 8221 lib/FHEM/Devices/GoE/GoECharger.pm
|
41
hooks/pre-commit
Executable file
41
hooks/pre-commit
Executable file
@ -0,0 +1,41 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use File::Basename;
|
||||
use POSIX qw(strftime);
|
||||
use strict;
|
||||
|
||||
my @filenames = (
|
||||
'FHEM/73_GoECharger.pm',
|
||||
'lib/FHEM/Devices/GoE/GoECharger.pm',
|
||||
'www/images/fhemSVG/goecharger.svg'
|
||||
);
|
||||
|
||||
my $controlsfile = 'controls_GoECharger.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;
|
325
lib/FHEM/Devices/GoE/GoECharger.pm
Normal file
325
lib/FHEM/Devices/GoE/GoECharger.pm
Normal file
@ -0,0 +1,325 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Developed with love
|
||||
#
|
||||
# (c) 2022-2022 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::Devices::GoE::GoECharger;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
#use POSIX;
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
|
||||
use FHEM::Meta;
|
||||
use GPUtils qw(GP_Import);
|
||||
use HttpUtils;
|
||||
#use FHEM::Core::Authentication::Passwords 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> GoECharger}
|
||||
if ( scalar( @{$aArg} ) != 2 );
|
||||
|
||||
my $name = shift @$aArg;
|
||||
$hash->{URL} = AttrVal( $name, 'LiberoIP', 'http://192.168.0.1:81');
|
||||
$hash->{INTERVAL} = 60;
|
||||
$hash->{NOTIFYDEV} = "global,$name";
|
||||
$hash->{VERSION} = version->parse($VERSION)->normal;
|
||||
|
||||
CommandAttr( undef, $name . ' room GoEChargero' )
|
||||
if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
|
||||
|
||||
readingsSingleUpdate( $hash, 'state', 'initialized', 1 );
|
||||
|
||||
|
||||
Log3($name, 3, qq{GoECharger ($name) - defined GoECharger});
|
||||
|
||||
### create password object to handle pass keystore
|
||||
$hash->{helper}->{passObj} = FHEM::Core::Authentication::Passwords->new($hash->{TYPE});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Undef {
|
||||
my $hash = shift;
|
||||
my $name = shift;
|
||||
|
||||
$hash->{helper}->{passObj}->setDeletePassword($name);
|
||||
RemoveInternalTimer($hash);
|
||||
|
||||
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{GoECharger ($name) - disabled});
|
||||
}
|
||||
elsif ( $cmd eq 'del' ) {
|
||||
readingsSingleUpdate( $hash, 'state', 'active', 1 );
|
||||
Log3($name, 3, qq{GoECharger ($name) - enabled});
|
||||
}
|
||||
}
|
||||
elsif ( $attrName eq 'interval' ) {
|
||||
if ( $cmd eq 'set' ) {
|
||||
return 'Interval must be greater than 0'
|
||||
if ( $attrVal == 0 );
|
||||
RemoveInternalTimer($hash);
|
||||
$hash->{INTERVAL} = $attrVal;
|
||||
Log3 $name, 3,
|
||||
qq{GoECharger ($name) - set interval: $attrVal};
|
||||
}
|
||||
elsif ( $cmd eq 'del' ) {
|
||||
RemoveInternalTimer($hash);
|
||||
$hash->{INTERVAL} = 60;
|
||||
Log3 $name, 3,
|
||||
qq{GoECharger ($name) - delete User interval and set default: 60};
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
// Notify stuff
|
||||
|
||||
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};
|
||||
|
||||
if ( lc $cmd eq 'password' ) {
|
||||
return qq{error set foo bar first}
|
||||
if ( AttrVal( $name, 'foobar', 'none' ) eq 'none' );
|
||||
|
||||
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) );
|
||||
# do stuff
|
||||
}
|
||||
else {
|
||||
my $list = 'password ';
|
||||
# more setter if password and foobar available
|
||||
$list .= 'foo:noArg bar:noArg'
|
||||
if ( defined(ReadPassword( $hash, $name ))
|
||||
&& AttrVal( $name, 'foobar', 'none' ) ne 'none'
|
||||
);
|
||||
|
||||
return "Unknown argument $cmd, choose one of $list";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Delete {
|
||||
my $hash = shift;
|
||||
my $name = shift;
|
||||
|
||||
$hash->{helper}->{passObj}->setDeletePassword($name);
|
||||
return;
|
||||
}
|
||||
|
||||
sub setSettings {
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Write( $hash, 'settings', undef, undef );
|
||||
|
||||
}
|
||||
|
||||
sub getSettings {
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
Write( $hash, undef, undef, undef );
|
||||
}
|
||||
|
||||
sub Write {
|
||||
my ( $hash, $payload ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my ( $header, $uri, $method );
|
||||
|
||||
( $payload, $header, $uri, $method ) =
|
||||
createHttpValueStrings( $hash, $payload );
|
||||
|
||||
HttpUtils_NonblockingGet(
|
||||
{
|
||||
url => $hash->{URL} . $uri,
|
||||
timeout => 15,
|
||||
hash => $hash,
|
||||
data => $payload,
|
||||
method => $method,
|
||||
keepalive => 1,
|
||||
header => $header,
|
||||
ignoreredirects => 1,
|
||||
doTrigger => 1,
|
||||
callback => \&ErrorHandling
|
||||
}
|
||||
);
|
||||
|
||||
Log3 $name, 4,
|
||||
"GoECharger ($name) - Send with URL: $hash->{URL}$uri, HEADER: secret!, DATA: secret!, METHOD: $method";
|
||||
|
||||
# Log3($name, 3,
|
||||
# "GoECharger ($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;
|
||||
|
||||
Log3 $name, 4, "GoECharger ($name) - ErrorHandling ".$data;
|
||||
# add internal timer
|
||||
#InternalTimer( gettimeofday() + $hash->{INTERVAL}, "FHEM::Devices::GoE::GoECharger::sub_procudure", $hash )
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub createHttpValueStrings {
|
||||
my ( $hash, $payload ) = @_;
|
||||
my $name = $hash->{NAME};
|
||||
|
||||
my $header = "Content-Type: application/x-www-form-urlencoded";
|
||||
my $uri = '';
|
||||
my $method = 'POST';
|
||||
$payload = '' if (!defined ($payload));
|
||||
|
||||
return ( $payload, $header, $uri, $method );
|
||||
}
|
||||
|
||||
####################################
|
||||
####################################
|
||||
#### my little helpers Sub's #######
|
||||
|
||||
sub ReadPassword {
|
||||
my $hash = shift;
|
||||
my $name = shift;
|
||||
|
||||
my $password;
|
||||
|
||||
Log3 $name, 4, "GoECharger ($name) - Read password from file";
|
||||
$password = $hash->{helper}->{passObj}->getReadPassword($name);
|
||||
|
||||
if ( defined($password) ) {
|
||||
return $password;
|
||||
} else {
|
||||
Log3 $name, 3, "GoECharger ($name) - No password in file";
|
||||
return undef;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Rename {
|
||||
my $new = shift;
|
||||
my $old = shift;
|
||||
|
||||
my $hash = $defs{$new};
|
||||
|
||||
$hash->{helper}->{passObj}->getRename($new,$old);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user