Example #1
0
    def _service_discovered(self, service: mdns.Service,
                            response: mdns.Response) -> None:
        if service.address is None or service.port == 0:
            return

        result = self._services[service.type][0](service, response)
        if result:
            name, base_service = result
            _LOGGER.debug(
                "Auto-discovered %s at %s:%d via %s (%s)",
                service.name,
                service.address,
                service.port,
                base_service.protocol,
                service.properties,
            )

            if service.address not in self._found_devices:
                self._found_devices[service.address] = FoundDevice(
                    name,
                    service.address,
                    response.deep_sleep,
                    lookup_internal_name(response.model),
                    [],
                )
            self._found_devices[service.address].services.append(base_service)

        # Save properties for all services belonging to a device/address
        if service.address is not None:
            if service.address not in self._properties:
                self._properties[service.address] = {}
            self._properties[service.address][
                service.type] = service.properties
Example #2
0
File: scan.py Project: NebzHB/pyatv
    def _handle_service(
        self,
        address,
        name: str,
        service: interface.BaseService,
        response: mdns.Response,
    ) -> None:
        _LOGGER.debug(
            "Auto-discovered %s at %s:%d (%s)",
            name,
            address,
            service.port,
            service.protocol,
        )

        if address not in self._found_devices:
            # Extract properties from extra services that might be of interest
            extra_properties: Dict[str, str] = {}
            for extra_service in EXTRA_SERVICES:
                extra_properties.update(
                    _get_service_properties(response.services, extra_service))

            self._found_devices[address] = conf.AppleTV(
                address,
                name,
                deep_sleep=response.deep_sleep,
                model=lookup_internal_name(response.model),
                properties=extra_properties,
            )

        self._found_devices[address].add_service(service)
Example #3
0
    def _handle_service(
        self,
        address,
        name: str,
        service: interface.BaseService,
        response: mdns.Response,
    ) -> None:
        _LOGGER.debug(
            "Auto-discovered %s at %s:%d (%s)",
            name,
            address,
            service.port,
            service.protocol,
        )

        self._found_devices.setdefault(
            address,
            conf.AppleTV(
                address,
                name,
                deep_sleep=response.deep_sleep,
                model=lookup_internal_name(response.model),
            ),
        ).add_service(service)
Example #4
0
def test_lookup_internal_name(internal_name, expected_model):
    assert lookup_internal_name(internal_name) == expected_model
Example #5
0
def test_lookup_missing_internal_name():
    assert lookup_internal_name("bad_name") == DeviceModel.Unknown
Example #6
0
def test_lookup_existing_internal_name():
    assert lookup_internal_name("J105aAP") == DeviceModel.Gen4K