Beispiel #1
0
 def test_protocol_str(self):
     self.assertEqual('MRP',
                      convert.protocol_str(Protocol.MRP))
     self.assertEqual('DMAP',
                      convert.protocol_str(Protocol.DMAP))
     self.assertEqual('AirPlay',
                      convert.protocol_str(Protocol.AirPlay))
Beispiel #2
0
 def test_protocol_str(self):
     self.assertEqual('MRP',
                      convert.protocol_str(const.PROTOCOL_MRP))
     self.assertEqual('DMAP',
                      convert.protocol_str(const.PROTOCOL_DMAP))
     self.assertEqual('AirPlay',
                      convert.protocol_str(const.PROTOCOL_AIRPLAY))
    async def async_step_pair_with_pin(self, user_input=None):
        """Handle pairing step where a PIN is required from the user."""
        errors = {}
        if user_input is not None:
            try:
                self.pairing.pin(user_input[CONF_PIN])
                await self.pairing.finish()
                self.credentials[
                    self.protocol.value] = self.pairing.service.credentials
                return await self.async_begin_pairing()
            except exceptions.PairingError:
                _LOGGER.exception("Authentication problem")
                errors["base"] = "auth"
            except AbortFlow:
                raise
            except Exception:  # pylint: disable=broad-except
                _LOGGER.exception("Unexpected exception")
                errors["base"] = "unknown"

        return self.async_show_form(
            step_id="pair_with_pin",
            data_schema=INPUT_PIN_SCHEMA,
            errors=errors,
            description_placeholders={
                "protocol": convert.protocol_str(self.protocol)
            },
        )
 async def async_step_protocol_disabled(self, user_input=None):
     """Inform user that a protocol is disabled and cannot be paired."""
     if user_input is not None:
         return await self.async_pair_next_protocol()
     return self.async_show_form(
         step_id="protocol_disabled",
         description_placeholders={"protocol": protocol_str(self.protocol)},
     )
    async def async_step_service_problem(self, user_input=None):
        """Inform user that a service will not be added."""
        if user_input is not None:
            return await self.async_pair_next_protocol()

        return self.async_show_form(
            step_id="service_problem",
            description_placeholders={"protocol": protocol_str(self.protocol)},
        )
    async def async_step_password(self, user_input=None):
        """Inform user that password is not supported."""
        if user_input is not None:
            return await self.async_pair_next_protocol()

        return self.async_show_form(
            step_id="password",
            description_placeholders={"protocol": protocol_str(self.protocol)},
        )
Beispiel #7
0
    async def async_step_service_problem(self, user_input=None):
        """Inform user that a service will not be added."""
        if user_input is not None:
            self.credentials[self.protocol.value] = None
            return await self.async_begin_pairing()

        return self.async_show_form(
            step_id="service_problem",
            description_placeholders={"protocol": convert.protocol_str(self.protocol)},
        )
    async def async_step_pair_no_pin(self, user_input=None):
        """Handle step where user has to enter a PIN on the device."""
        from pyatv import convert

        if user_input is not None:
            if self._pairing.has_paired:
                await self._pairing.close()
                return await self.async_begin_pairing()
            return self.async_abort(reason="device_did_not_pair")

        random_pin = randrange(1000, stop=10000)
        self._pairing.pin(random_pin)
        return self.async_show_form(
            step_id="pair_no_pin",
            description_placeholders={
                "protocol": convert.protocol_str(self._protocol),
                "pin": random_pin
                })
Beispiel #9
0
    async def async_step_pair_no_pin(self, user_input=None):
        """Handle step where user has to enter a PIN on the device."""
        if user_input is not None:
            await self.pairing.finish()
            if self.pairing.has_paired:
                self.credentials[self.protocol.value] = self.pairing.service.credentials
                return await self.async_begin_pairing()

            await self.pairing.close()
            return self.async_abort(reason="device_did_not_pair")

        pin = randrange(1000, stop=10000)
        self.pairing.pin(pin)
        return self.async_show_form(
            step_id="pair_no_pin",
            description_placeholders={
                "protocol": convert.protocol_str(self.protocol),
                "pin": pin,
            },
        )
Beispiel #10
0
def test_protocol_str():
    assert "MRP" == convert.protocol_str(Protocol.MRP)
    assert "DMAP" == convert.protocol_str(Protocol.DMAP)
    assert "AirPlay" == convert.protocol_str(Protocol.AirPlay)
Beispiel #11
0
def test_protocol_str(protocol, output):
    assert convert.protocol_str(protocol) == output
Beispiel #12
0
 def test_protocol_str(self):
     self.assertEqual("MRP", convert.protocol_str(Protocol.MRP))
     self.assertEqual("DMAP", convert.protocol_str(Protocol.DMAP))
     self.assertEqual("AirPlay", convert.protocol_str(Protocol.AirPlay))
Beispiel #13
0
 def test_unknown_protocol_str(self):
     self.assertEqual("Unknown", convert.protocol_str("invalid"))
Beispiel #14
0
def test_protocol_str():
    assert "MRP" == convert.protocol_str(Protocol.MRP)
    assert "DMAP" == convert.protocol_str(Protocol.DMAP)
    assert "AirPlay" == convert.protocol_str(Protocol.AirPlay)
    assert "Companion" == convert.protocol_str(Protocol.Companion)
    assert "RAOP" == convert.protocol_str(Protocol.RAOP)
Beispiel #15
0
def test_unknown_protocol_str():
    assert "Unknown" == convert.protocol_str("invalid")
Beispiel #16
0
 def __str__(self):
     """Return a string representation of this object."""
     return 'Protocol: {0}, Port: {1}, Credentials: {2}'.format(
         convert.protocol_str(self.protocol), self.port,
         self.credentials)
Beispiel #17
0
 def test_unknown_protocol_str(self):
     self.assertEqual('Unknown', convert.protocol_str('invalid'))