2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 23:06:37 +00:00

00_MQTT: fixed delete MQTT device, added setKeyValue/getKeyValue for username and password

git-svn-id: https://svn.fhem.de/fhem/trunk@13177 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
eisler 2017-01-22 07:46:14 +00:00
parent 620dc5fe4e
commit 6b8535470b
2 changed files with 36 additions and 10 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- bufix: 00_MQTT: fixed delete MQTT device
added setKeyValue/getKeyValue for username and password
- changed: 49_SSCAM: compatibility to SVS 8.0.0 - changed: 49_SSCAM: compatibility to SVS 8.0.0
- bugfix: 74_XiaomiFlowerSens 0.4.1, bugfix new error handling - bugfix: 74_XiaomiFlowerSens 0.4.1, bugfix new error handling
- update: 88_HMCCU: version 3.8 - update: 88_HMCCU: version 3.8

View File

@ -87,6 +87,8 @@ BEGIN {GP_Import(qw(
AttrVal AttrVal
Log3 Log3
AssignIoPort AssignIoPort
getKeyValue
setKeyValue
))}; ))};
sub Define($$) { sub Define($$) {
@ -97,6 +99,18 @@ sub Define($$) {
$hash->{timeout} = 60; $hash->{timeout} = 60;
$hash->{messages} = {}; $hash->{messages} = {};
my ($host,$username,$password) = split("[ \t]+", $hash->{DEF});
$hash->{DeviceName} = $host;
my $name = $hash->{NAME};
my $user = getKeyValue($name."_user");
my $pass = getKeyValue($name."_pass");
setKeyValue($name."_user",$username) unless(defined($user));
setKeyValue($name."_pass",$password) unless(defined($pass));
$hash->{DEF} = $host;
if ($main::init_done) { if ($main::init_done) {
return Start($hash); return Start($hash);
} else { } else {
@ -105,7 +119,12 @@ sub Define($$) {
} }
sub Undef($) { sub Undef($) {
Stop(shift); my $hash = shift;
Stop($hash);
my $name = $hash->{NAME};
setKeyValue($name."_user",undef);
setKeyValue($name."_pass",undef);
return undef;
} }
sub Set($@) { sub Set($@) {
@ -158,14 +177,6 @@ sub Attr($$$$) {
sub Start($) { sub Start($) {
my $hash = shift; my $hash = shift;
my ($dev,$username,$password) = split("[ \t]+", $hash->{DEF});
$hash->{DeviceName} = $dev;
if(defined($username) && $username ne "") {
$hash->{username} = $username;
}
if(defined($password) && $password ne "") {
$hash->{password} = $password;
}
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
return DevIo_OpenDev($hash, 0, "MQTT::Init"); return DevIo_OpenDev($hash, 0, "MQTT::Init");
} }
@ -183,6 +194,16 @@ sub Ready($) {
return DevIo_OpenDev($hash, 1, "MQTT::Init") if($hash->{STATE} eq "disconnected"); return DevIo_OpenDev($hash, 1, "MQTT::Init") if($hash->{STATE} eq "disconnected");
} }
sub Rename() {
my ($new,$old) = @_;
setKeyValue($new."_user",getKeyValue($old."_user"));
setKeyValue($new."_pass",getKeyValue($old."_pass"));
setKeyValue($old."_user",undef);
setKeyValue($old."_pass",undef);
return undef;
}
sub Init($) { sub Init($) {
my $hash = shift; my $hash = shift;
send_connect($hash); send_connect($hash);
@ -342,7 +363,10 @@ sub Read {
sub send_connect($) { sub send_connect($) {
my $hash = shift; my $hash = shift;
return send_message($hash, message_type => MQTT_CONNECT, keep_alive_timer => $hash->{timeout}, user_name => $hash->{username}, password => $hash->{password}); my $name = $hash->{NAME};
my $user = getKeyValue($name."_user");
my $pass = getKeyValue($name."_pass");
return send_message($hash, message_type => MQTT_CONNECT, keep_alive_timer => $hash->{timeout}, user_name => $user, password => $pass);
}; };
sub send_publish($@) { sub send_publish($@) {