V0.4 - HMRPC: Fehlermeldung statt Abbruch, wenn eine Testverbindung zum

entsprechenden Daemon nicht moeglich ist
       HMRPC: Beim Abmelden wird nun korrekterweise kein Callback-Parameter
       uebergeben
       HMRPC: Das Default-Timeout fuer eingehende Requests ist nun auf 20s
       gesetzt, da die 3s bei sehr grossen eingehenden Requests offenbar
       zu kurz war und so z.B. der initiale newDevices-Aufruf nach dem init
       abgebrochen wurde, was zu einem Absturz des rfd fuehrt
       HMRPC: Ist ein Channel unbekannt, wird nun der Event an das entsprechende
       Device delegiert, fuer Channel != 0 dann mit dem Suffix _ChannelID
       (z.B. STATE_1)
       HMRPC: PRESS_ loest nun wirklich jedesmal ein changed aus.
       import_webui: Pattern korrigiert, so dass nun auch die virtuellen
       Taster erkannt werden



git-svn-id: https://fhem.svn.sourceforge.net/svnroot/fhem/trunk/fhem@1107 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
oliverwagner
2011-11-13 19:59:18 +00:00
parent 2aceb6ac49
commit 9231e3855e
4 changed files with 90 additions and 27 deletions

View File

@@ -1,11 +1,11 @@
##############################################
###########################################################
#
# HomeMatic XMLRPC API Device Provider
# Written by Oliver Wagner <owagner@vapor.com>
#
# V0.3
# V0.4
#
##############################################
###########################################################
#
# This module implements the documented XML-RPC based API
# of the Homematic system software (currently offered as
@@ -46,7 +46,11 @@ HMRPC_Shutdown($)
{
my ($hash) = @_;
# Uninitialize again
$hash->{client}->send_request("init",$hash->{callbackurl},"");
if($hash->{callbackurl})
{
Log(2,"HMRPC unitializing callback ".$hash->{callbackurl});
$hash->{client}->send_request("init",$hash->{callbackurl});
}
return undef;
}
@@ -81,7 +85,10 @@ HMRPC_Define($$)
# Add the XMLRPC methods we do expose
$hash->{server}->add_method(
{name=>"event",signature=> ["string string string string int","string string string string double","string string string string boolean"],code=>\&HMRPC_EventCB}
{name=>"event",signature=> ["string string string string int","string string string string double","string string string string boolean","string string string string i4"],code=>\&HMRPC_EventCB}
);
$hash->{server}->add_method(
{name=>"newDevices",signature=>["array string array"],code=>\&HMRPC_NewDevicesCB }
);
#
# Dummy implementation, always return an empty array
@@ -89,12 +96,6 @@ HMRPC_Define($$)
$hash->{server}->add_method(
{name=>"listDevices",signature=>["array string"],code=>sub{return RPC::XML::array->new()} }
);
#
# TOFIX! We can use this to store device types, autocreate devices and other niceties
#
$hash->{server}->add_method(
{name=>"newDevices",signature=>["array string array"],code=>sub{return RPC::XML::array->new()} }
);
$hash->{STATE} = "Initialized";
$hash->{SERVERSOCKET}=$hash->{server}->{__daemon};
@@ -143,18 +144,45 @@ HMRPC_RegisterCallback($)
# and then look at the local socket address assigned to us.
#
my $dummysock=IO::Socket::INET->new(PeerAddr=>$hash->{serveraddr},PeerPort=>$hash->{serverport});
$hash->{callbackurl}="http://".$dummysock->sockhost().":".$hash->{PORT}."/fhemhmrpc";
if(!$dummysock)
{
Log(2,"HMRPC unable to connect to ".$hash->{serveraddr}.":".$hash->{serverport}." ($!), will retry later");
return;
}
$hash->{callbackurl}="http://".$dummysock->sockhost().":".$hash->{PORT}."/fh";
$dummysock->close();
Log(2, "HMRPC callback listening on $hash->{callbackurl}");
# We need to fork here, as the xmlrpc server will synchronously call us
if(!fork())
{
$hash->{client}->send_request("init",$hash->{callbackurl},"cb");
Log(2, "HMRPC callback initialized");
$hash->{client}->send_request("init",$hash->{callbackurl},"CB1");
Log(2, "HMRPC callback with URL ".$hash->{callbackurl}." initialized");
exit(0);
}
}
#####################################
# Process device info
sub
HMRPC_NewDevicesCB($$$)
{
my ($server, $cb, $a) = @_;
my $hash=$server->{fhemdef};
Log(2,"HMRPC received ".scalar(@$a)." device specifications");
# We receive an array of hashes with the device information. We
# store those hashes again in a hash, keyed by address, for later
# use by the individual devices
for my $dev (@$a)
{
my $addr=$dev->{ADDRESS};
$hash->{devicespecs}{$addr}=$dev;
}
return RPC::XML::array->new();
}
#####################################
sub
HMRPC_EventCB($$$$$)
@@ -175,7 +203,7 @@ HMRPC_Read($)
# Handle an incoming callback
#
my $conn=$hash->{server}->{__daemon}->accept();
$conn->timeout(3);
$conn->timeout(20);
$hash->{server}->process_request($conn);
$conn->close;
undef $conn;