2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-09 20:57:11 +00:00

73_GardenaSmartBridge: add support for power plug, Installer and META

git-svn-id: https://svn.fhem.de/fhem/trunk@19037 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
LeonGaultier 2019-03-26 11:22:21 +00:00
parent be16e6ec5d
commit 525166b0f6
3 changed files with 168 additions and 32 deletions

View File

@ -1,5 +1,7 @@
# 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.
- feature: 74_GardenaSmartDevice: add support for power plug and META
- feature: 73_GardenaSmartBridge: add support for power plug and META
- feature: 42_AptToDate: add support for META and Installer Modules
- bugfix: 98_WeekdayTimer: fix problem if use more then one holiday2we entry
- bugfix: 42_AptToDate: fix Can't call method readFromChild

View File

@ -2,7 +2,7 @@
#
# Developed with Kate
#
# (c) 2017-2018 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
# (c) 2017-2019 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
# All rights reserved
#
# Special thanks goes to comitters:
@ -58,7 +58,7 @@ package main;
use strict;
use warnings;
my $version = "1.4.0";
my $version = "1.6.0";
sub GardenaSmartBridge_Initialize($) {
@ -66,19 +66,19 @@ sub GardenaSmartBridge_Initialize($) {
my ($hash) = @_;
# Provider
$hash->{WriteFn} = "GardenaSmartBridge::Write";
$hash->{WriteFn} = "FHEM::GardenaSmartBridge::Write";
$hash->{Clients} = ":GardenaSmartDevice:";
$hash->{MatchList} = { "1:GardenaSmartDevice" => '^{"id":".*' };
# Consumer
$hash->{SetFn} = "GardenaSmartBridge::Set";
$hash->{DefFn} = "GardenaSmartBridge::Define";
$hash->{UndefFn} = "GardenaSmartBridge::Undef";
$hash->{DeleteFn} = "GardenaSmartBridge::Delete";
$hash->{RenameFn} = "GardenaSmartBridge::Rename";
$hash->{NotifyFn} = "GardenaSmartBridge::Notify";
$hash->{SetFn} = "FHEM::GardenaSmartBridge::Set";
$hash->{DefFn} = "FHEM::GardenaSmartBridge::Define";
$hash->{UndefFn} = "FHEM::GardenaSmartBridge::Undef";
$hash->{DeleteFn} = "FHEM::GardenaSmartBridge::Delete";
$hash->{RenameFn} = "FHEM::GardenaSmartBridge::Rename";
$hash->{NotifyFn} = "FHEM::GardenaSmartBridge::Notify";
$hash->{AttrFn} = "GardenaSmartBridge::Attr";
$hash->{AttrFn} = "FHEM::GardenaSmartBridge::Attr";
$hash->{AttrList} =
"debugJSON:0,1 "
. "disable:1 "
@ -92,10 +92,12 @@ sub GardenaSmartBridge_Initialize($) {
my $hash = $modules{GardenaSmartBridge}{defptr}{$d};
$hash->{VERSION} = $version;
}
return FHEM::Meta::InitMod( __FILE__, $hash );
}
package GardenaSmartBridge;
use GPUtils qw(:all)
package FHEM::GardenaSmartBridge;
use GPUtils qw(GP_Import)
; # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
my $missingModul = "";
@ -145,6 +147,7 @@ sub Define($$) {
my @a = split( "[ \t][ \t]*", $def );
return $@ unless ( FHEM::Meta::SetInternals($hash) );
return "too few parameters: define <NAME> GardenaSmartBridge"
if ( @a != 2 );
return
@ -155,7 +158,7 @@ sub Define($$) {
$hash->{BRIDGE} = 1;
$hash->{URL} = 'https://sg-api.dss.husqvarnagroup.net/sg-1';
$hash->{VERSION} = $version;
$hash->{INTERVAL} = 300;
$hash->{INTERVAL} = 60;
$hash->{NOTIFYDEV} = "global,$name";
CommandAttr( undef, $name . ' room GardenaSmart' )
@ -234,9 +237,9 @@ sub Attr(@) {
elsif ( $cmd eq "del" ) {
RemoveInternalTimer($hash);
$hash->{INTERVAL} = 300;
$hash->{INTERVAL} = 60;
Log3 $name, 3,
"GardenaSmartBridge ($name) - delete User interval and set default: 300";
"GardenaSmartBridge ($name) - delete User interval and set default: 60";
}
}
@ -301,7 +304,7 @@ sub Notify($$) {
{
InternalTimer( gettimeofday() + $hash->{INTERVAL},
"GardenaSmartBridge::getDevices", $hash );
"FHEM::GardenaSmartBridge::getDevices", $hash );
Log3 $name, 4,
"GardenaSmartBridge ($name) - set internal timer function for recall getDevices sub";
}
@ -383,6 +386,8 @@ sub Write($@) {
Log3 $name, 4,
"GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: secret!, DATA: secret!, METHOD: $method";
# Log3 $name, 3,
# "GardenaSmartBridge ($name) - Send with URL: $hash->{URL}$uri, HEADER: $header, DATA: $payload, METHOD: $method";
}
sub ErrorHandling($$$) {
@ -468,7 +473,7 @@ sub ErrorHandling($$$) {
readingsBulkUpdate( $dhash, "state", "the command is processed",
1 );
InternalTimer( gettimeofday() + 5, "GardenaSmartBridge::getDevices", $hash, 1 );
InternalTimer( gettimeofday() + 5, "FHEM::GardenaSmartBridge::getDevices", $hash, 1 );
}
elsif ( $param->{code} != 200 ) {
@ -979,6 +984,21 @@ sub createHttpValueStrings($@) {
. '/properties/watering_timer_'
. $valve_id;
}
elsif ( defined($abilities)
and defined($payload)
and $abilities eq 'power' )
{
my $valve_id;
$method = 'PUT';
$uri .=
'/devices/'
. $deviceId
. '/abilities/'
. $abilities
. '/properties/power_timer';
}
else {
$uri .=
@ -1065,7 +1085,7 @@ sub DeletePassword($) {
<ul>
<li>debugJSON - </li>
<li>disable - Disables the Bridge</li>
<li>interval - Interval in seconds (Default=300)</li>
<li>interval - Interval in seconds (Default=60)</li>
<li>gardenaAccountEmail - Email Adresse which was used in the GardenaAPP</li>
</ul>
</ul>
@ -1126,11 +1146,58 @@ sub DeletePassword($) {
<b>Attribute</b>
<ul>
<li>debugJSON - JSON Fehlermeldungen</li>
<li>disable - Schaltet die Daten&uuml;bertragung der Bridge ab</li>
<li>disable - Schaltet die Datenübertragung der Bridge ab</li>
<li>interval - Abfrageinterval in Sekunden (default: 300)</li>
<li>gardenaAccountEmail - Email Adresse, die auch in der GardenaApp verwendet wurde</li>
</ul>
</ul>
=end html_DE
=for :application/json;q=META.json 73_GardenaSmartBridge.pm
{
"abstract": "Modul to communicate with the GardenaCloud",
"x_lang": {
"de": {
"abstract": "Modul zur Datenübertragung zur GardenaCloud"
}
},
"keywords": [
"fhem-mod-device",
"fhem-core",
"Garden",
"Gardena",
"Smart"
],
"release_status": "stable",
"license": "GPL_2",
"author": [
"Marko Oldenburg <leongaultier@gmail.com>"
],
"x_fhem_maintainer": [
"CoolTux"
],
"x_fhem_maintainer_github": [
"LeonGaultier"
],
"prereqs": {
"runtime": {
"requires": {
"FHEM": 5.00918799,
"perl": 5.016,
"Meta": 0,
"IO::Socket::SSL": 0,
"JSON": 0,
"HttpUtils": 0,
"Encode": 0
},
"recommends": {
},
"suggests": {
}
}
}
}
=end :application/json;q=META.json
=cut

View File

@ -2,7 +2,7 @@
#
# Developed with Kate
#
# (c) 2017-2018 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
# (c) 2017-2019 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
# All rights reserved
#
# Special thanks goes to comitters:
@ -58,7 +58,7 @@ package main;
use strict;
use warnings;
my $version = "1.4.0";
my $version = "1.6.0";
sub GardenaSmartDevice_Initialize($) {
@ -66,15 +66,15 @@ sub GardenaSmartDevice_Initialize($) {
$hash->{Match} = '^{"id":".*';
$hash->{SetFn} = "GardenaSmartDevice::Set";
$hash->{DefFn} = "GardenaSmartDevice::Define";
$hash->{UndefFn} = "GardenaSmartDevice::Undef";
$hash->{ParseFn} = "GardenaSmartDevice::Parse";
$hash->{SetFn} = "FHEM::GardenaSmartDevice::Set";
$hash->{DefFn} = "FHEM::GardenaSmartDevice::Define";
$hash->{UndefFn} = "FHEM::GardenaSmartDevice::Undef";
$hash->{ParseFn} = "FHEM::GardenaSmartDevice::Parse";
$hash->{AttrFn} = "GardenaSmartDevice::Attr";
$hash->{AttrFn} = "FHEM::GardenaSmartDevice::Attr";
$hash->{AttrList} =
"readingValueLanguage:de,en "
. "model:watering_computer,sensor,mower,ic24 "
. "model:watering_computer,sensor,mower,ic24,power "
. "IODev "
. $readingFnAttributes;
@ -83,12 +83,14 @@ sub GardenaSmartDevice_Initialize($) {
my $hash = $modules{GardenaSmartDevice}{defptr}{$d};
$hash->{VERSION} = $version;
}
return FHEM::Meta::InitMod( __FILE__, $hash );
}
## unserer packagename
package GardenaSmartDevice;
package FHEM::GardenaSmartDevice;
use GPUtils qw(:all)
use GPUtils qw(GP_Import)
; # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
my $missingModul = "";
@ -126,6 +128,7 @@ sub Define($$) {
my ( $hash, $def ) = @_;
my @a = split( "[ \t]+", $def );
return $@ unless ( FHEM::Meta::SetInternals($hash) );
return
"too few parameters: define <NAME> GardenaSmartDevice <device_Id> <model>"
if ( @a < 3 );
@ -238,7 +241,7 @@ sub Set($@) {
SetPredefinedStartPoints( $hash, @args );
return $err if ( defined($err) );
### watering_computer
### watering_computer
}
elsif ( lc $cmd eq 'manualoverride' ) {
@ -251,8 +254,15 @@ sub Set($@) {
$payload = '"name":"cancel_override"';
### Watering ic24
}
elsif ( lc $cmd eq 'on' or lc $cmd eq 'off' or lc $cmd eq 'on-for-timer' ) {
my $val = ( defined($args[0]) ? join( " ", @args ) : lc $cmd );
$payload =
'"properties":{"value":"' . $val . '"}';
}
### Watering ic24
elsif ( $cmd =~ /manualDurationValve/ ) {
my $valve_id;
@ -304,6 +314,8 @@ sub Set($@) {
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
$list .= 'refresh:temperature,light,humidity'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'sensor' );
$list .= 'on:noArg off:noArg on-for-timer:slider,0,1,3600'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
return "Unknown argument $cmd, choose one of $list";
}
@ -315,6 +327,8 @@ sub Set($@) {
if ( AttrVal( $name, 'model', 'unknown' ) eq 'watering_computer' );
$abilities = 'watering'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
$abilities = 'power'
if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
$hash->{helper}{deviceAction} = $payload;
readingsSingleUpdate( $hash, "state", "send command to gardena cloud", 1 );
@ -542,10 +556,18 @@ sub WriteReadings($$) {
. (
ReadingsVal(
$name, 'scheduling-scheduled_watering_next_start',
'readingsValError'
'no timer'
)
)
) if ( AttrVal( $name, 'model', 'unknown' ) eq 'ic24' );
readingsBulkUpdate(
$hash, 'state',
ReadingsVal(
$name, 'power-power_timer',
'no info from power-timer'
)
) if ( AttrVal( $name, 'model', 'unknown' ) eq 'power' );
readingsEndUpdate( $hash, 1 );
@ -1090,4 +1112,49 @@ sub SetPredefinedStartPoints($@) {
</ul>
=end html_DE
=for :application/json;q=META.json 74_GardenaSmartDevice.pm
{
"abstract": "Modul to control GardenaSmart Devices",
"x_lang": {
"de": {
"abstract": "Modul zur Steuerung von Gardena Smart Ger&aumlten"
}
},
"keywords": [
"fhem-mod-device",
"fhem-core",
"Garden",
"Gardena",
"Smart"
],
"release_status": "stable",
"license": "GPL_2",
"author": [
"Marko Oldenburg <leongaultier@gmail.com>"
],
"x_fhem_maintainer": [
"CoolTux"
],
"x_fhem_maintainer_github": [
"LeonGaultier"
],
"prereqs": {
"runtime": {
"requires": {
"FHEM": 5.00918799,
"perl": 5.016,
"Meta": 0,
"JSON": 0,
"Time::Local": 0
},
"recommends": {
},
"suggests": {
}
}
}
}
=end :application/json;q=META.json
=cut