mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-03 16:56:54 +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:
parent
620dc5fe4e
commit
6b8535470b
@ -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.
|
||||
- bufix: 00_MQTT: fixed delete MQTT device
|
||||
added setKeyValue/getKeyValue for username and password
|
||||
- changed: 49_SSCAM: compatibility to SVS 8.0.0
|
||||
- bugfix: 74_XiaomiFlowerSens 0.4.1, bugfix new error handling
|
||||
- update: 88_HMCCU: version 3.8
|
||||
|
@ -87,6 +87,8 @@ BEGIN {GP_Import(qw(
|
||||
AttrVal
|
||||
Log3
|
||||
AssignIoPort
|
||||
getKeyValue
|
||||
setKeyValue
|
||||
))};
|
||||
|
||||
sub Define($$) {
|
||||
@ -97,6 +99,18 @@ sub Define($$) {
|
||||
$hash->{timeout} = 60;
|
||||
$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) {
|
||||
return Start($hash);
|
||||
} else {
|
||||
@ -105,7 +119,12 @@ sub Define($$) {
|
||||
}
|
||||
|
||||
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($@) {
|
||||
@ -158,14 +177,6 @@ sub Attr($$$$) {
|
||||
|
||||
sub Start($) {
|
||||
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);
|
||||
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");
|
||||
}
|
||||
|
||||
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($) {
|
||||
my $hash = shift;
|
||||
send_connect($hash);
|
||||
@ -342,7 +363,10 @@ sub Read {
|
||||
|
||||
sub send_connect($) {
|
||||
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($@) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user