Пример #1
0
    def device_info(self) -> DeviceInfo:
        """Return general device information."""
        properties = self._all_properties()

        if Protocol.MRP in self._services:
            os_type = OperatingSystem.TvOS
        elif Protocol.DMAP in self._services:
            os_type = OperatingSystem.Legacy
        else:
            os_type = OperatingSystem.Unknown

        build = properties.get("SystemBuildVersion")
        version = properties.get("osvers", lookup_version(build))

        model_name: Optional[str] = properties.get("model", None)
        if model_name:
            model = lookup_model(model_name)
        else:
            model = self._model

        mac = properties.get("macAddress", properties.get("deviceid"))
        if mac:
            mac = mac.upper()

        return DeviceInfo(os_type, version, build, model, mac)
Пример #2
0
    def version(self) -> Optional[str]:
        """Operating system version."""
        if self._version:
            return self._version

        version = lookup_version(self.build_number)
        if version:
            return version

        return self._version
Пример #3
0
    def device_info(self) -> DeviceInfo:
        """Return general device information."""
        properties = self._all_properties()

        build: Optional[str] = properties.get("systembuildversion")
        version = properties.get("ov")
        if not version:
            version = properties.get("osvers", lookup_version(build))

        model_name: Optional[str] = properties.get("model",
                                                   properties.get("am"))
        if model_name:
            model = lookup_model(model_name)
        else:
            model = self._model

        # MRP devices run tvOS (as far as we know now) as well as HomePods for
        # some reason
        if Protocol.MRP in self._services or model in [
                DeviceModel.HomePod,
                DeviceModel.HomePodMini,
        ]:
            os_type = OperatingSystem.TvOS
        elif Protocol.DMAP in self._services:
            os_type = OperatingSystem.Legacy
        elif model in [
                DeviceModel.AirPortExpress, DeviceModel.AirPortExpressGen2
        ]:
            os_type = OperatingSystem.AirPortOS
        else:
            os_type = OperatingSystem.Unknown

        mac = properties.get("macaddress", properties.get("deviceid"))
        if mac:
            mac = mac.upper()

        # The waMA property comes from the _airport._tcp.local service, announced by
        # AirPort Expresses (used by the admin tool). It contains various information,
        # for instance MAC address and software version.
        wama = properties.get("wama")
        if wama:
            props: Mapping[str, str] = dict(
                cast(Tuple[str, str], prop.split("=", maxsplit=1))
                for prop in ("macaddress=" + wama).split(","))
            if not mac:
                mac = props["macaddress"].replace("-", ":").upper()
            version = props.get("syVs")

        return DeviceInfo(os_type, version, build, model, mac)
Пример #4
0
def device_info(service_type: str, properties: Mapping[str,
                                                       Any]) -> Dict[str, Any]:
    """Return device information from zeroconf properties."""
    devinfo: Dict[str, Any] = {}
    if "systembuildversion" in properties:
        devinfo[DeviceInfo.BUILD_NUMBER] = properties["systembuildversion"]

        version = lookup_version(properties["systembuildversion"])
        if version:
            devinfo[DeviceInfo.VERSION] = version
    if "macaddress" in properties:
        devinfo[DeviceInfo.MAC] = properties["macaddress"]

    # MRP has only been seen on Apple TV and HomePod, which both run tvOS,
    # so an educated guess is made here. It is border line OK, but will
    # do for now.
    devinfo[DeviceInfo.OPERATING_SYSTEM] = OperatingSystem.TvOS

    return devinfo
Пример #5
0
def test_lookup_existing_version(version, expected_version):
    assert lookup_version(version) == expected_version
Пример #6
0
def test_lookup_guess_major_version():
    assert lookup_version("16F123") == "12.x"
    assert lookup_version("17F123") == "13.x"
Пример #7
0
def test_lookup_bad_version():
    assert not lookup_version(None)
    assert not lookup_version("bad_version")
Пример #8
0
def test_lookup_existing_version():
    assert lookup_version("17J586") == "13.0"
Пример #9
0
 def test_lookup_guess_major_version(self):
     self.assertEqual(lookup_version("16F123"), "12.x")
     self.assertEqual(lookup_version("17F123"), "13.x")
Пример #10
0
 def test_lookup_bad_version(self):
     self.assertIsNone(lookup_version(None))
     self.assertIsNone(lookup_version("bad_version"))
Пример #11
0
 def test_lookup_existing_version(self):
     self.assertEqual(lookup_version("17J586"), "13.0")