def test_simple_pprint(): elem = tags.uint8_tag("uuu8", 12) inner = tags.container_tag("conb", elem) in_data = tags.container_tag("cona", inner) parsed = parser.parse(in_data, lookup_tag) assert (parser.pprint(parsed, lookup_tag) == "cona: [container, container]\n" " conb: [container, container 2]\n" " uuu8: 12 [uint, uint8]\n")
def test_parse_value_in_container(): in_data = tags.container_tag( "cona", tags.uint8_tag("uuu8", 36) + tags.uint16_tag("uu16", 13000)) parsed = parser.parse(in_data, lookup_tag) assert 1 == len(parsed) inner = parser.first(parsed, "cona") assert 2 == len(inner) assert 36 == parser.first(inner, "uuu8") assert 13000 == parser.first(inner, "uu16")
def test_parse_uint_of_various_lengths(): in_data = (tags.uint8_tag("uuu8", 12) + tags.uint16_tag("uu16", 37888) + tags.uint32_tag("uu32", 305419896) + tags.uint64_tag("uu64", 8982983289232)) parsed = parser.parse(in_data, lookup_tag) assert 4 == len(parsed) assert 12 == parser.first(parsed, "uuu8") assert 37888 == parser.first(parsed, "uu16") assert 305419896 == parser.first(parsed, "uu32") assert 8982983289232 == parser.first(parsed, "uu64")
async def handle_playstatus(self, request): """Handle playstatus (currently playing) requests.""" self._verify_auth_parameters(request) body = b"" playing = self.state.playing # Check if connection should be closed to trigger error on client side if playing.force_close: await request.transport.close() # Make sure revision matches revision = int(request.rel_url.query["revision-number"]) if playing.revision != revision: # Not a valid response as a real device, just to make tests fail return web.Response(status=500) if playing.playback_rate is not None: # TODO : Magic constants if math.isclose(playing.playback_rate, 0.0): playstatus = 3 elif math.isclose(playing.playback_rate, 1.0): playstatus = 4 elif playing.playback_rate > 0.0: playstatus = 6 else: playstatus = 5 body += tags.uint32_tag("caps", playstatus) elif playing.paused is not None: body += tags.uint32_tag("caps", 3 if playing.paused else 4) elif playing.playstatus is not None: body += tags.uint32_tag("caps", playing.playstatus) if playing.title is not None: body += tags.string_tag("cann", playing.title) if playing.artist is not None: body += tags.string_tag("cana", playing.artist) if playing.album is not None: body += tags.string_tag("canl", playing.album) if playing.genre is not None: body += tags.string_tag("cang", playing.genre) if playing.total_time is not None: total_time = playing.total_time * 1000 # sec -> ms body += tags.uint32_tag("cast", total_time) if playing.position is not None: pos = playing.total_time - playing.position body += tags.uint32_tag("cant", pos * 1000) # sec -> ms if playing.mediakind is not None: body += tags.uint32_tag("cmmk", playing.mediakind) if playing.repeat is not None: body += tags.uint8_tag("carp", playing.repeat.value) if playing.shuffle is not None: body += tags.uint8_tag("cash", playing.shuffle.value) if self.state.volume_controls is not None: body += tags.uint8_tag("cavc", self.state.volume_controls) body += tags.uint32_tag("cmsr", playing.revision + 1) return web.Response(body=tags.container_tag("cmst", body), status=200)
def test_ignore_value(): elem = tags.uint8_tag("igno", 44) parsed = parser.parse(elem, lookup_tag) assert parser.first(parsed, "igno") is None
def test_extract_simplified_container(): elem = tags.uint8_tag("uuu8", 12) inner = tags.container_tag("conb", elem) in_data = tags.container_tag("cona", inner) parsed = parser.parse(in_data, lookup_tag) assert 12 == parser.first(parsed, "cona", "conb", "uuu8")
def _move(direction, time, point1, point2): data = f"touch{direction}&time={time}&point={point1},{point2}" return tags.uint8_tag("cmcc", 0x30) + tags.string_tag("cmbe", data)
def controlprompt_cmd(self, cmd): """Perform a "controlpromptentry" command.""" data = tags.string_tag("cmbe", cmd) + tags.uint8_tag("cmcc", 0) return self.daap.post(_CTRL_PROMPT_CMD, data=data)