declension / squeeze-alexa

Squeezebox integration for Amazon Alexa
GNU General Public License v3.0
59 stars 20 forks source link

server status command generate KeyError: 'name' #93

Closed zepab closed 5 years ago

zepab commented 5 years ago

Hi, many thanks for all the work done on this project. I have encountered some issue which need code changes on my side. Issue is linked to the server status answer linked to my LMS installation (lms running on synology nas). A long time ago I had some squeezebox device which are no longer on my network enhance a different status answer (see below the 'sn player count': 2) which cause a parsing error (some entrie have no name key). To fix the error I first update the code as follow: inside server.py use the self.player_names

print_d("Found {total} player(s): {players}",
                total=len(self.players),
                players=self.player_names)

This avoid the parsing error but then wrongly overwrite the third device named salon with 'Squeezebox Radio Fanal' To have a clean fix I had to use a different command to get the player list:

        #response = self.__a_request("serverstatus 0 99", raw=True)
        #prefer using players otherwise it give some trouble with ghost player not connected for a long time
        response = self.__a_request("players 0 99", raw=True)

here below the log with the initial faillure:

Refreshing server and player statuses...
<<<< serverstatus 0 99
>>>> serverstatus 0 99 lastscan%3A1536990512 version%3A7.9.1 uuid%3Aa6abbce0-edfe-447d-9c4b-2f132345733f mac%3A00%3A11%3A32%3A42%3AC2%3A92 info%20total%20albums%3A107 info%20total%20artists%3A209 info%20total%20genres%3A13 info%20total%20songs%3A2151 info%20total%20duration%3A534087.510000002 player%20count%3A3 playerindex%3A0 playerid%3A00%3A04%3A20%3A29%3Ae5%3Ad1 uuid%3Ab1a5d6e01890c4c440d2da913233e622 ip%3A192.168.168.173%3A35566 name%3ACuisine seq_no%3A180 model%3Ababy modelname%3ASqueezebox%20Radio power%3A0 isplaying%3A0 displaytype%3Anone isplayer%3A1 canpoweroff%3A1 connected%3A1 firmware%3A7.7.3-r16676 playerindex%3A1 playerid%3A00%3A04%3A20%3A2e%3A4d%3Ab6 uuid%3Afeeaab78bf7d9d4773495e7112eefaff ip%3A192.168.168.134%3A34510 name%3AChambre seq_no%3A73 model%3Ababy modelname%3ASqueezebox%20Radio power%3A0 isplaying%3A0 displaytype%3Anone isplayer%3A1 canpoweroff%3A1 connected%3A1 firmware%3A7.7.3-r16676 playerindex%3A2 playerid%3A00%3A04%3A20%3A23%3A71%3Af6 uuid%3A8d470575086e09c3995a5fcb7a1667c8 ip%3A192.168.168.186%3A39845 name%3ASalon seq_no%3A17 model%3Afab4 modelname%3ASqueezebox%20Touch power%3A0 isplaying%3A0 displaytype%3Anone isplayer%3A1 canpoweroff%3A1 connected%3A1 firmware%3A7.8.0-r16754 sn%20player%20count%3A2 id%3A31579863 name%3ASqueezebox%20Radio%20Fanal playerid%3A00%3A04%3A20%3A2e%3A63%3Ac2 model%3Ababy id%3A11266387 name%3ASqueezebox%20Radio%20Meme playerid%3A00%3A04%3A20%3A2b%3A26%3A5a model%3Ababy other%20player%20count%3A0
Player(s): dict_values([{'playerid': '00:04:20:29:e5:d1', 'uuid': 'b1a5d6e01890c4c440d2da913233e622', 'ip': '192.168.168.173:35566', 'name': 'Cuisine', 'seq_no': 180, 'model': 'baby', 'modelname': 'Squeezebox Radio', 'power': False, 'isplaying': False, 'displaytype': 'none', 'isplayer': True, 'canpoweroff': True, 'connected': True, 'firmware': '7.7.3-r16676', 'playerindex': 1}, {'playerid': '00:04:20:2e:4d:b6', 'uuid': 'feeaab78bf7d9d4773495e7112eefaff', 'ip': '192.168.168.134:34510', 'name': 'Chambre', 'seq_no': 73, 'model': 'baby', 'modelname': 'Squeezebox Radio', 'power': False, 'isplaying': False, 'displaytype': 'none', 'isplayer': True, 'canpoweroff': True, 'connected': True, 'firmware': '7.7.3-r16676', 'playerindex': 2}, {'playerid': '00:04:20:23:71:f6', 'uuid': '8d470575086e09c3995a5fcb7a1667c8', 'ip': '192.168.168.186:39845', 'name': 'Squeezebox Radio Fanal', 'seq_no': 17, 'model': 'fab4', 'modelname': 'Squeezebox Touch', 'power': False, 'isplaying': False, 'displaytype': 'none', 'isplayer': True, 'canpoweroff': True, 'connected': True, 'firmware': '7.8.0-r16754', 'sn player count': 2, 'id': 31579863}, {'playerid': '00:04:20:2e:63:c2', 'model': 'baby', 'id': 11266387, 'name': 'Squeezebox Radio Meme'}, {'playerid': '00:04:20:2b:26:5a', 'model': 'baby', 'other player count': 0}])
Traceback (most recent call last):
File "/var/task/handler.py", line 42, in lambda_handler
sqa = SqueezeAlexa(server=server or get_server(),
File "/var/task/handler.py", line 34, in get_server
debug=LMS_SETTINGS.debug)
File "/var/task/squeezealexa/squeezebox/server.py", line 75, in create
inst = type(self)._INSTANCE = Server(transport, *args, **kwargs)
File "/var/task/squeezealexa/squeezebox/server.py", line 99, in __init__
self.refresh_status()
File "/var/task/squeezealexa/squeezebox/server.py", line 236, in refresh_status
players=[p['name'] for p in self.players.values()])
File "/var/task/squeezealexa/squeezebox/server.py", line 236, in <listcomp>
players=[p['name'] for p in self.players.values()])
KeyError: 'name'
Goodbye from <squeezealexa.squeezebox.server.Server object at 0x7f72da8c0358>

Thanks and Regards.

declension commented 5 years ago

Thanks for the report. Looks like a bug with parsing, I'll have a look. Are you happy for me to use that data above in unit testing?

declension commented 5 years ago

See related #28

zepab commented 5 years ago

Thanks for the report. Looks like a bug with parsing, I'll have a look. Are you happy for me to use that data above in unit testing?

yes I'm fine with it. may be you can replace some digit form the mac address and uuid to make it a little annonymous.

declension commented 5 years ago

yes I'm fine with it. may be you can replace some digit form the mac address and uuid to make it a little annonymous.

Great. Yes I was going to do this actually.