2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

mqtt2.template:sonos2mqtt minor changes,99_sonos2mqttUtils change parameter handling

git-svn-id: https://svn.fhem.de/fhem/trunk@23886 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
Otto123 2021-03-04 08:51:11 +00:00
parent 4f78832e7d
commit 51719212b7
2 changed files with 13 additions and 30 deletions

View File

@ -4354,31 +4354,17 @@ set DEVICE attrTemplate sonos2mqtt_bridge
attr DEVICE getList Favorites:noArg Favorites {sonos2mqtt($NAME,$EVENT)}
attr DEVICE setList PauseAll:noArg $\DEVICETOPIC/cmd/pauseall\
CheckSubscription:noArg $\DEVICETOPIC/cmd/check-subscriptions
attr SonosBridge userReadings favlist:Favorites.* {\
use JSON;use HTML::Entities;use Encode qw(encode decode);\
my $enc = 'UTF8';\
my @out;\
my $decoded = decode_json(ReadingsVal($name,'Favorites',''));\
my @arr = @{$decoded->{'Result'}};;\
foreach (@arr) {\
my $dec = encode($enc, decode_entities($_->{'Title'}));\
$dec =~ s/\s/./g;\
push @out,$dec}\
return join ',', sort @out},\
grouplist:Favorites.* {\
my @out;\
foreach (devspec2array('a:model=sonos2mqtt_speaker')) {if (ReadingsVal($_,'isMaster','')) {push @out,ReadingsVal($_,'name','')}}\
return join(',', sort @out)}
{sonos2mqtt_mod_list('a:model=sonos2mqtt_bridge','readingList',AttrVal("DEVICE","devicetopic",'sonos').'/RINCON_([0-9A-Z]+)/Favorites:.* Favorites')}
{sonos2mqtt_mod_list('a:model=sonos2mqtt_bridge','readingList',AttrVal("DEVICE","devicetopic",'sonos').'/RINCON_([0-9A-Z]+)/Reply:.* Reply')}
attr SonosBridge userReadings favlist:Favorites.* {sonos2mqtt_ur($name,'favlist')},\
grouplist:Favorites.* {sonos2mqtt_ur($name,'grouplist')}
{sonos2mqtt_setup('a:model=sonos2mqtt_bridge')}
defmod n_configSonos notify global:DEFINED.MQTT2_RINCON_[A-Z0-9]+|MQTT2_RINCON_[A-Z0-9]+:IPAddress:.* {sonos2mqtt_nty($NAME,$EVENT)}
setreading DEVICE attrTemplateVersion 20210301
setreading DEVICE attrTemplateVersion 20210303
name:sonos2mqtt_speaker
desc:A basic sonos2mqtt speaker device, Forum #111711 and Wiki
filter:TYPE=MQTT2_DEVICE
order:M_05b
par:BASE_TOPIC;base topic set in configuration.yaml of the sonos2mqtt bridge;{ AttrVal("DEVICE","devicetopic",AttrVal("DEVICE","readingList","")) =~ m,[\b]?([^\/:]+)[\/].+, ? $1 : undef }
par:BASE_TOPIC;base topic set in configuration.yaml of the sonos2mqtt bridge;{ AttrVal("DEVICE","devicetopic",'sonos') }
par:DEV_ID;techname of the device ;{ AttrVal("DEVICE","readingList","") =~ m,[^\/]+[\/](RINCON_[0-9A-Z]+):.*, ? $1 : undef }
par:ALIAS;friendly name as set in sonos gadget itself;{ ReadingsVal("DEVICE","name","unknown") }
par:DEVNAME;friendly name, used for topic in lowercase;{ lc(ReadingsVal("DEVICE","name","unknown")) }
@ -4399,13 +4385,10 @@ attr DEVICE userReadings Master:groupName.* {(split(' +',ReadingsVal($name,'grou
isMaster:coordinatorUuid.* {ReadingsVal($name,'coordinatorUuid','') eq ReadingsVal($name,'uuid','')?1:0},\
inGroup:groupName.* {ReadingsVal($name,'groupName','') =~ / \+ /?1:0},\
inCouple:coordinatorUuid.* {(ReadingsVal($name,'coordinatorUuid','') ne ReadingsVal($name,'uuid','') and (index(ReadingsVal($name,'groupName',''), ReadingsVal($name,'name','')) != -1))?1:0},\
Input:currentTrack_TrackUri.* {my $currentTrack_TrackUri = ReadingsVal($name,'currentTrack_TrackUri','');\
$currentTrack_TrackUri =~ 'x-rincon-stream'\
? 'LineIn': $currentTrack_TrackUri =~ 'spdif'\
? 'TV' : ReadingsVal($name,'enqueuedMetadata_UpnpClass','') eq 'object.item.audioItem.audioBroadcast'\
? 'Radio' : 'Playlist'}
Input:currentTrack_TrackUri.* {sonos2mqtt_ur($name,'Input')}
set DEVICE x_raw_payload {"command": "adv-command","input": {"cmd":"GetZoneInfo","reply":"ZoneInfo"}}
setreading DEVICE attrTemplateVersion 20210302
setreading DEVICE attrTemplateVersion 20210303
###########################################

View File

@ -113,7 +113,7 @@ return '';
####### devStateIcon
sub sonos2mqtt_devStateIcon
{
my ($name) = @_;
my $name = shift // return'';
my $wpix = '210px';
my $master = ReadingsVal($name,'Master',$name);
my $inGroup = ReadingsNum($name,'inGroup','0');
@ -173,7 +173,7 @@ return ''
#### Setup some additional features in speaker and bridge
sub sonos2mqtt_setup
{
my $devspec = shift @_ // 'a:model=sonos2mqtt_speaker';
my $devspec = shift || 'a:model=sonos2mqtt_speaker';
my $bridge = (devspec2array('a:model=sonos2mqtt_bridge'))[0];
if ($devspec eq 'a:model=sonos2mqtt_bridge'){
@ -197,11 +197,11 @@ my @line = ("S5","Z90","ZP120");
if (!ReadingsVal($bridge,'favlist',0)) {my $fav = fhem("get $bridge Favorites")}
for (devspec2array($devspec)) {
my $mn = ReadingsVal($_,'modelNumber','');
fhem("set $_ volume ".ReadingsVal($_,'volume','10')); # trick to initiate the userReadings
if (grep {/$mn/} @tv) {sonos2mqtt_mod_list($_,'setList','input:Queue,TV'.q( {sonos2mqtt($NAME,$EVENT)}))}
if (grep {/$mn/} @line) {sonos2mqtt_mod_list($_,'setList','input:Queue,Line_In'.q( {sonos2mqtt($NAME,$EVENT)}))}
sonos2mqtt_mod_list($_,'setList','joinGroup:'.ReadingsVal($bridge,'grouplist','').q( {sonos2mqtt($NAME,$EVENT)}));
sonos2mqtt_mod_list($_,'setList','playFav:'.ReadingsVal($bridge,'favlist','').q( {sonos2mqtt($NAME,$EVENT)}));
fhem("set $_ volumeUp; set $_ volumeDown"); # trick to initiate the userReadings
}
return ''
}
@ -236,8 +236,8 @@ return ''
#
sub sonos2mqtt_ur
{
my $name = shift @_ // 'name';
my $reading = shift @_ // 'reading';
my $name = shift // return '';
my $reading = shift || 'reading';
my @out;
if ($reading eq 'grouplist'){