Skip to content

Commit

Permalink
core: Update device info
Browse files Browse the repository at this point in the history
Add Apple TV 1, update some tables and fix OS bug.

Relates to #2517
  • Loading branch information
postlund committed Nov 3, 2024
1 parent 658fd06 commit d925073
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 20 deletions.
19 changes: 12 additions & 7 deletions docs/api/pyatv.const.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h4><code><a title="pyatv.const.DeviceModel" href="#pyatv.const.DeviceModel">Dev
<li><code><a title="pyatv.const.DeviceModel.AirPortExpressGen2" href="#pyatv.const.DeviceModel.AirPortExpressGen2">AirPortExpressGen2</a></code></li>
<li><code><a title="pyatv.const.DeviceModel.AppleTV4KGen2" href="#pyatv.const.DeviceModel.AppleTV4KGen2">AppleTV4KGen2</a></code></li>
<li><code><a title="pyatv.const.DeviceModel.AppleTV4KGen3" href="#pyatv.const.DeviceModel.AppleTV4KGen3">AppleTV4KGen3</a></code></li>
<li><code><a title="pyatv.const.DeviceModel.AppleTVGen1" href="#pyatv.const.DeviceModel.AppleTVGen1">AppleTVGen1</a></code></li>
<li><code><a title="pyatv.const.DeviceModel.Gen2" href="#pyatv.const.DeviceModel.Gen2">Gen2</a></code></li>
<li><code><a title="pyatv.const.DeviceModel.Gen3" href="#pyatv.const.DeviceModel.Gen3">Gen3</a></code></li>
<li><code><a title="pyatv.const.DeviceModel.Gen4" href="#pyatv.const.DeviceModel.Gen4">Gen4</a></code></li>
Expand Down Expand Up @@ -224,7 +225,7 @@ <h1 class="title">Module <code>pyatv.const</code></h1>
</header>
<section id="section-intro">
<p>Constants used in the public API.</p>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L1-L457" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L1-L460" class="git-link">Browse git</a></div>
</section>
<section>
</section>
Expand All @@ -243,7 +244,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
<section class="desc"><p>Hardware device model.</p>
<p>Gen2-Gen4K are Apple TV model names and will be renamed to AppleTVGenX in the
future.</p></section>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L150-L194" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L150-L197" class="git-link">Browse git</a></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>enum.Enum</li>
Expand All @@ -266,6 +267,10 @@ <h3>Class variables</h3>
<dd>
<section class="desc"><p>Device model is seventh generation Apple TV (Apple TV 4K gen 3).</p></section>
</dd>
<dt id="pyatv.const.DeviceModel.AppleTVGen1"><code class="name">var <span class="ident">AppleTVGen1</span> = 13</code></dt>
<dd>
<section class="desc"><p>Device model is first generation Apple TV.</p></section>
</dd>
<dt id="pyatv.const.DeviceModel.Gen2"><code class="name">var <span class="ident">Gen2</span> = 1</code></dt>
<dd>
<section class="desc"><p>Device model is second generation Apple TV (Apple TV 2).</p></section>
Expand Down Expand Up @@ -349,7 +354,7 @@ <h3>Class variables</h3>
</code></dt>
<dd>
<section class="desc"><p>All supported features.</p></section>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L249-L448" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L252-L451" class="git-link">Browse git</a></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>enum.Enum</li>
Expand Down Expand Up @@ -628,7 +633,7 @@ <h3>Class variables</h3>
</code></dt>
<dd>
<section class="desc"><p>State of a particular feature.</p></section>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L229-L245" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L232-L248" class="git-link">Browse git</a></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>enum.Enum</li>
Expand Down Expand Up @@ -660,7 +665,7 @@ <h3>Class variables</h3>
</code></dt>
<dd>
<section class="desc"><p>Type of input when pressing a button.</p></section>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L197-L207" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L200-L210" class="git-link">Browse git</a></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>enum.Enum</li>
Expand Down Expand Up @@ -785,7 +790,7 @@ <h3>Class variables</h3>
</code></dt>
<dd>
<section class="desc"><p>Pairing requirement for a service.</p></section>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L210-L226" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L213-L229" class="git-link">Browse git</a></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>enum.Enum</li>
Expand Down Expand Up @@ -936,7 +941,7 @@ <h3>Class variables</h3>
</code></dt>
<dd>
<section class="desc"><p>Touch action constants.</p></section>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L451-L457" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/const.py#L454-L460" class="git-link">Browse git</a></div>
<h3>Ancestors</h3>
<ul class="hlist">
<li>enum.Enum</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/pyatv.convert.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1 class="title">Module <code>pyatv.convert</code></h1>
</header>
<section id="section-intro">
<p>Various types of extraction and conversion functions.</p>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/convert.py#L1-L80" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/convert.py#L1-L81" class="git-link">Browse git</a></div>
</section>
<section>
</section>
Expand Down
3 changes: 3 additions & 0 deletions pyatv/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class DeviceModel(Enum):
HomePodGen2 = 12
"""Device model is HomePod (second generation)."""

AppleTVGen1 = 13
"""Device model is first generation Apple TV."""


class InputAction(Enum):
"""Type of input when pressing a button."""
Expand Down
1 change: 1 addition & 0 deletions pyatv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def protocol_str(protocol: Protocol) -> str:
def model_str(device_model: DeviceModel) -> str:
"""Convert device model to string."""
return {
DeviceModel.AppleTVGen1: "Apple TV 1",
DeviceModel.Gen2: "Apple TV 2",
DeviceModel.Gen3: "Apple TV 3",
DeviceModel.Gen4: "Apple TV 4",
Expand Down
55 changes: 46 additions & 9 deletions pyatv/support/device_info.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Lookup methods for device data."""

import re
from typing import Dict, Optional
from typing import Dict, Optional, Union

from pyatv.const import DeviceModel, OperatingSystem

_MODEL_LIST: Dict[str, DeviceModel] = {
"AirPort4,107": DeviceModel.AirPortExpress,
"AirPort10,115": DeviceModel.AirPortExpressGen2,
"AppleTV1,1": DeviceModel.AppleTVGen1,
"AppleTV2,1": DeviceModel.Gen2,
"AppleTV3,1": DeviceModel.Gen3,
"AppleTV3,2": DeviceModel.Gen3,
Expand All @@ -18,6 +19,7 @@
"AudioAccessory1,1": DeviceModel.HomePod,
"AudioAccessory1,2": DeviceModel.HomePod,
"AudioAccessory5,1": DeviceModel.HomePodMini,
"AudioAccessorySingle5,1": DeviceModel.HomePodMini,
"AudioAccessory6,1": DeviceModel.HomePodGen2,
}

Expand Down Expand Up @@ -72,6 +74,18 @@
"20L497": "16.4",
"20L498": "16.4.1",
"20L563": "16.5",
"20M73": "16.6",
"22J354": "17.0",
"21K69": "17.1",
"21K365": "17.2",
"21K646": "17.3",
"21L227": "17.4",
"21L569": "17.5",
"21L580": "17.5.1",
"21M71": "17.6",
"21M80": "17.6.1",
"22J357": "18.0",
"22J580": "18.1",
}

_OS_IDENTIFIER_FORMATS = [
Expand Down Expand Up @@ -113,14 +127,37 @@ def lookup_version(build: Optional[str]) -> Optional[str]:
return None


def lookup_os(identifier: str) -> OperatingSystem:
def lookup_os(id_or_model: Union[str, DeviceModel]) -> OperatingSystem:
"""Lookup operating system based on identifier.
An identifier has the format similar to "MacbookAir10,1". Only
macOS is supported here.
An identifier has the format similar to "MacbookAir10,1" or
a DeviceModel.
"""
return (
OperatingSystem.MacOS
if any(re.match(os_format, identifier) for os_format in _OS_IDENTIFIER_FORMATS)
else OperatingSystem.Unknown
)
if isinstance(id_or_model, str):
return (
OperatingSystem.MacOS
if any(
re.match(os_format, id_or_model) for os_format in _OS_IDENTIFIER_FORMATS
)
else OperatingSystem.Unknown
)

if id_or_model in [DeviceModel.AirPortExpress, DeviceModel.AirPortExpressGen2]:
return OperatingSystem.AirPortOS
if id_or_model in [
DeviceModel.HomePod,
DeviceModel.HomePodMini,
DeviceModel.HomePodGen2,
]:
return OperatingSystem.TvOS
if id_or_model in [DeviceModel.AppleTVGen1, DeviceModel.Gen2, DeviceModel.Gen3]:
return OperatingSystem.Legacy
if id_or_model in [
DeviceModel.Gen4,
DeviceModel.Gen4K,
DeviceModel.AppleTV4KGen2,
DeviceModel.AppleTV4KGen3,
]:
return OperatingSystem.TvOS

return OperatingSystem.Unknown

Check warning on line 163 in pyatv/support/device_info.py

View check run for this annotation

Codecov / codecov/patch

pyatv/support/device_info.py#L163

Added line #L163 was not covered by tests
18 changes: 15 additions & 3 deletions tests/support/test_device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_lookup_existing_version(version, expected_version):


@pytest.mark.parametrize(
"identifier,expected_os",
"id_or_model,expected_os",
[
("bad", OperatingSystem.Unknown),
("MacBookAir10,1", OperatingSystem.MacOS),
Expand All @@ -58,7 +58,19 @@ def test_lookup_existing_version(version, expected_version):
("MacBookPro5,67", OperatingSystem.MacOS),
("Mac1,4", OperatingSystem.MacOS),
("MacPro19,4", OperatingSystem.MacOS),
(DeviceModel.AirPortExpress, OperatingSystem.AirPortOS),
(DeviceModel.AirPortExpressGen2, OperatingSystem.AirPortOS),
(DeviceModel.HomePod, OperatingSystem.TvOS),
(DeviceModel.HomePodGen2, OperatingSystem.TvOS),
(DeviceModel.HomePodMini, OperatingSystem.TvOS),
(DeviceModel.AppleTVGen1, OperatingSystem.Legacy),
(DeviceModel.Gen2, OperatingSystem.Legacy),
(DeviceModel.Gen3, OperatingSystem.Legacy),
(DeviceModel.Gen4, OperatingSystem.TvOS),
(DeviceModel.Gen4K, OperatingSystem.TvOS),
(DeviceModel.AppleTV4KGen2, OperatingSystem.TvOS),
(DeviceModel.AppleTV4KGen3, OperatingSystem.TvOS),
],
)
def test_lookup_os(identifier, expected_os):
assert lookup_os(identifier) == expected_os
def test_lookup_os(id_or_model, expected_os):
assert lookup_os(id_or_model) == expected_os
1 change: 1 addition & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_protocol_str(protocol, output):
@pytest.mark.parametrize(
"model,output",
[
(DeviceModel.AppleTVGen1, "Apple TV 1"),
(DeviceModel.Gen2, "Apple TV 2"),
(DeviceModel.Gen3, "Apple TV 3"),
(DeviceModel.Gen4, "Apple TV 4"),
Expand Down

0 comments on commit d925073

Please sign in to comment.