2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

98_weekprofile: new command get associations

git-svn-id: https://svn.fhem.de/fhem/trunk@21059 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Risiko 2020-01-26 16:07:14 +00:00
parent d1c7c00389
commit 34017c2a68
2 changed files with 59 additions and 2 deletions

View File

@ -1,6 +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.
- feature: 6.0 released - feature: 98_weekprofile: new command get associations
- feature: 6.0 released
- 2020-01-26 (6.0) - 2020-01-26 (6.0)
- new: MSwitch_Wizard: preparation for Mswitch V3.0 - new: MSwitch_Wizard: preparation for Mswitch V3.0

View File

@ -814,6 +814,50 @@ sub weekprofile_Get($$@)
} }
return $names; return $names;
} }
#-----------------------------------------------------------------------------
$list .= ' associations:0,1' if ($useTopics);
if($cmd eq "associations") {
my $retType = 1;
$retType = $params[0] if(@params >= 1);
my @not_asso = ();
my @json_arr = ();
my $retHTML = "<table><thead><tr>";
$retHTML .= "<th width='150'><b>Device</b></th><th width='150'><b>Profile</b></th></tr>";
$retHTML .= "<th>&nbsp;</th><th></th></tr>";
$retHTML .= "</thead><tbody>";
foreach my $dev (@{$hash->{SNDDEVLIST}}) {
my $entry = {};
$entry->{DEVICE}->{NAME} = $dev->{NAME};
$entry->{PROFILE}->{NAME} = "";
my $prfName = AttrVal($dev->{NAME},"weekprofile",undef);
if (!defined($prfName)) {
push @not_asso, $dev->{NAME};
push @json_arr , $entry;
next;
}
my ($prf,$idx) = weekprofile_findPRF($hash, $prfName, undef, 0);
my $color = defined($prf) ? "" : "color:red" ;
$entry->{PROFILE}->{NAME} = $prfName;
$entry->{PROFILE}->{EXISTS} = defined($prf) + 0;
push @json_arr , $entry;
$retHTML .= "<tr><td style='text-align:left'>$dev->{NAME}</td><td style='text-align:center;$color'>$prfName</td></tr>";
}
$retHTML .= "<tr><td colspan='2'><i>Not associated devices</i></td></tr>" if (scalar(@not_asso));
foreach my $devname (@not_asso) {
$retHTML .= "<tr><td style='text-align:left'>$devname</td><td style='text-align:center'></td></tr>";
}
$retHTML.= "</tbody></table>";
my $ret = $retHTML;
if ($retType == 1) {
my $json_text = undef;
my $json = JSON->new->allow_nonref;
eval { $json_text = $json->encode(\@json_arr) };
$ret = $json_text;
}
return $ret;
}
if($cmd eq "sndDevList") { if($cmd eq "sndDevList") {
my $json = JSON->new->allow_nonref; my $json = JSON->new->allow_nonref;
@ -842,9 +886,11 @@ sub weekprofile_findPRF($$$$)
my $found = undef; my $found = undef;
my $idx = 0; my $idx = 0;
my $topicOk = 0;
foreach my $prf (@{$hash->{PROFILES}}){ foreach my $prf (@{$hash->{PROFILES}}){
if ( ($prf->{NAME} eq $name) && ($prf->{TOPIC} eq $topic) ){ $topicOk = defined($topic) ? ($prf->{TOPIC} eq $topic) : 1;
if ( ($prf->{NAME} eq $name) && $topicOk ){
$found = $prf; $found = $prf;
last; last;
} }
@ -1587,6 +1633,11 @@ sub weekprofile_getEditLNK_MasterDev($$)
<li>topic_names<br> <li>topic_names<br>
Return a comma seperated list of topic names. Return a comma seperated list of topic names.
</li> </li>
<li>associations [ReturnType (0|1)]<br>
Returns a list of supported devices with the associated profile.<br>
ReturnType 0: HTML table</br>
ReturnType 1: json list</br>
</li>
</ul> </ul>
<a name="weekprofilereadings"></a> <a name="weekprofilereadings"></a>
@ -1759,6 +1810,11 @@ sub weekprofile_getEditLNK_MasterDev($$)
</code> </code>
Ist name 'topicname:profilename' wird '0' der Name der Referenz zurück gegeben. Ist name 'topicname:profilename' wird '0' der Name der Referenz zurück gegeben.
</li> </li>
<li>associations [Rückgabetyp (0|1)]<br>
Gibt eine Liste der unterstützten Geräte mit dem verbundenen\zugeordnetem Profilnamen zurück.<br>
Rückgabetyp 0: HTML Tabelle</br>
Rückgabetyp 1: json Liste</br>
</li>
</ul> </ul>
<a name="weekprofilereadings"></a> <a name="weekprofilereadings"></a>