diff --git a/fhem/CHANGED b/fhem/CHANGED index 93aff4e31..a7bdac31f 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,6 +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. - - feature: 6.0 released + - feature: 98_weekprofile: new command get associations + - feature: 6.0 released - 2020-01-26 (6.0) - new: MSwitch_Wizard: preparation for Mswitch V3.0 diff --git a/fhem/FHEM/98_weekprofile.pm b/fhem/FHEM/98_weekprofile.pm index 49af2edc6..7f8e46830 100644 --- a/fhem/FHEM/98_weekprofile.pm +++ b/fhem/FHEM/98_weekprofile.pm @@ -814,6 +814,50 @@ sub weekprofile_Get($$@) } 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 = ""; + $retHTML .= ""; + $retHTML .= ""; + $retHTML .= ""; + 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 .= ""; + } + $retHTML .= "" if (scalar(@not_asso)); + foreach my $devname (@not_asso) { + $retHTML .= ""; + } + $retHTML.= "
DeviceProfile
 
$dev->{NAME}$prfName
Not associated devices
$devname
"; + 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") { my $json = JSON->new->allow_nonref; @@ -842,9 +886,11 @@ sub weekprofile_findPRF($$$$) my $found = undef; my $idx = 0; + my $topicOk = 0; 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; last; } @@ -1587,6 +1633,11 @@ sub weekprofile_getEditLNK_MasterDev($$)
  • topic_names
    Return a comma seperated list of topic names.
  • +
  • associations [ReturnType (0|1)]
    + Returns a list of supported devices with the associated profile.
    + ReturnType 0: HTML table
    + ReturnType 1: json list
    +
  • @@ -1759,6 +1810,11 @@ sub weekprofile_getEditLNK_MasterDev($$) Ist name 'topicname:profilename' wird '0' der Name der Referenz zurück gegeben. +
  • associations [Rückgabetyp (0|1)]
    + Gibt eine Liste der unterstützten Geräte mit dem verbundenen\zugeordnetem Profilnamen zurück.
    + Rückgabetyp 0: HTML Tabelle
    + Rückgabetyp 1: json Liste
    +