FIX: fixed not working without authentication

This commit is contained in:
Dominik Meyer 2024-02-25 13:22:22 +01:00
parent fc04cea1b5
commit 8490e7046f
Signed by: byterazor
GPG Key ID: EABDA0FD5981BC97
2 changed files with 26 additions and 5 deletions

View File

@ -165,9 +165,17 @@ sub NTFY_newSubscription
my $topic = shift; my $topic = shift;
my $newDeviceName = makeDeviceName($hash->{NAME} . "_" . $topic); my $newDeviceName = makeDeviceName($hash->{NAME} . "_" . $topic);
my $token = NFTY_Calc_Auth_Token($hash->{helper}->{PASSWORD},$hash->{USERNAME});
my $token;
fhem("define $newDeviceName NTFY_TOPIC " . $hash->{SERVER} . " " . $token . " " . $topic); if ($hash->{helper}->{PASSWORD})
{
$token= NFTY_Calc_Auth_Token($hash->{helper}->{PASSWORD},$hash->{USERNAME});
fhem("define $newDeviceName NTFY_TOPIC " . $hash->{SERVER} . " " . $token . " " . $topic);
}
else
{
fhem("define $newDeviceName NTFY_TOPIC " . $hash->{SERVER} . " " . $topic);
}
NTFY_Update_Subscriptions_Readings($hash); NTFY_Update_Subscriptions_Readings($hash);
} }

View File

@ -100,12 +100,25 @@ sub NTFY_TOPIC_Define
# parse parameters into array and hash # parse parameters into array and hash
my($params, $h) = parseParams($define); my($params, $h) = parseParams($define);
my $token;
my $topic;
if ($params->[4])
{
$topic = $params->[4];
$token = $params->[3]
}
else
{
$topic = $params->[3];
}
my $name = makeDeviceName($params->[0]); my $name = makeDeviceName($params->[0]);
$hash->{NAME} = $name; $hash->{NAME} = $name;
$hash->{SERVER} = $params->[2]; $hash->{SERVER} = $params->[2];
$hash->{helper}{authString} = $params->[3]; $hash->{helper}{authString} = $token;
$hash->{TOPIC} = $params->[4]; $hash->{TOPIC} = $topic;
$hash->{Clients} = "NTFY_CLIENT"; $hash->{Clients} = "NTFY_CLIENT";
$hash->{ClientsKeepOrder} = 1; $hash->{ClientsKeepOrder} = 1;
$hash->{STATE} = "unknown"; $hash->{STATE} = "unknown";