Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Askey STI6130 #354

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions androidtv/basetv/basetv.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ def _cmd_current_app(self):
):
return constants.CMD_CURRENT_APP_GOOGLE_TV

# Is this an Askey STI6130 Device?
if (
self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV
and "askey" in self.device_properties.get("manufacturer", "")
and "sti6130" in self.device_properties.get("product_id", "")
):
return constants.CMD_CURRENT_APP_ASKEY_STI6130

# Is this an Android 11 device?
if self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV and self.device_properties.get("sw_version", "") == "11":
return constants.CMD_CURRENT_APP11
Expand All @@ -193,6 +201,14 @@ def _cmd_current_app_media_session_state(self):
if constants.CUSTOM_CURRENT_APP_MEDIA_SESSION_STATE in self._custom_commands:
return self._custom_commands[constants.CUSTOM_CURRENT_APP_MEDIA_SESSION_STATE]

# Is this an Askey STI6130 Device?
if (
self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV
and "askey" in self.device_properties.get("manufacturer", "")
and "sti6130" in self.device_properties.get("product_id", "")
):
return constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE_ASKEY_STI6130

# Is this a Google Chromecast Android TV?
if (
self.DEVICE_ENUM == constants.DeviceEnum.ANDROIDTV
Expand Down Expand Up @@ -407,7 +423,7 @@ def _parse_device_properties(self, properties):
The output of the ADB command that retrieves the device properties

This method fills in the ``device_properties`` attribute, which is a dictionary with keys
``'serialno'``, ``'manufacturer'``, ``'model'``, and ``'sw_version'``
``'serialno'``, ``'manufacturer'``, ``'model'``, ``'sw_version'`` and ``'product_id'``

"""
_LOGGER.debug(
Expand All @@ -422,11 +438,11 @@ def _parse_device_properties(self, properties):
return

lines = properties.strip().splitlines()
if len(lines) != 4:
if len(lines) != 5:
self.device_properties = {}
return

manufacturer, model, serialno, version = lines
manufacturer, model, serialno, version, product_id = lines
prabhjotsbhatia-ca marked this conversation as resolved.
Show resolved Hide resolved

if not serialno.strip():
_LOGGER.warning(
Expand All @@ -442,6 +458,7 @@ def _parse_device_properties(self, properties):
"model": model,
"serialno": serialno,
"sw_version": version,
"product_id": product_id,
}

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion androidtv/basetv/basetv_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async def get_device_properties(self):
Returns
-------
props : dict
A dictionary with keys ``'wifimac'``, ``'ethmac'``, ``'serialno'``, ``'manufacturer'``, ``'model'``, and ``'sw_version'``
A dictionary with keys ``'wifimac'``, ``'ethmac'``, ``'serialno'``, ``'manufacturer'``, ``'model'``, ``'sw_version'`` and ``'product_id'``

"""
properties = await self._adb.shell(constants.CMD_DEVICE_PROPERTIES)
Expand Down
2 changes: 1 addition & 1 deletion androidtv/basetv/basetv_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def get_device_properties(self):
Returns
-------
props : dict
A dictionary with keys ``'wifimac'``, ``'ethmac'``, ``'serialno'``, ``'manufacturer'``, ``'model'``, and ``'sw_version'``
A dictionary with keys ``'wifimac'``, ``'ethmac'``, ``'serialno'``, ``'manufacturer'``, ``'model'``, ``'sw_version'`` and ``'product_id'``

"""
properties = self._adb.shell(constants.CMD_DEVICE_PROPERTIES)
Expand Down
20 changes: 19 additions & 1 deletion androidtv/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ class DeviceEnum(IntEnum):
#: Output identifier for current/focused application for an Android 13 device
CMD_CURRENT_APP13 = CMD_DEFINE_CURRENT_APP_VARIABLE13 + " && echo $CURRENT_APP"


#: Assign focused application identifier to ``CURRENT_APP`` variable (for a Askey STI6130 )
#: Tested on Bell Streamer which is sti6130. May also work the same on Walmart Onn android stick, which is the same hardware, but labelled Askey STI6140
CMD_DEFINE_CURRENT_APP_VARIABLE_ASKEY_STI6130 = (
"CURRENT_APP=$(dumpsys window windows | grep -E -m 1 'imeLayeringTarget|imeInputTarget|imeControlTarget') && "
+ CMD_PARSE_CURRENT_APP11
)

#: Output identifier for current/focused application (for a Askey STI6130)
CMD_CURRENT_APP_ASKEY_STI6130 = CMD_DEFINE_CURRENT_APP_VARIABLE_ASKEY_STI6130 + " && echo $CURRENT_APP "


#: Assign focused application identifier to ``CURRENT_APP`` variable (for a Google TV device)
CMD_DEFINE_CURRENT_APP_VARIABLE_GOOGLE_TV = (
"CURRENT_APP=$(dumpsys activity a . | grep mResumedActivity) && " + CMD_PARSE_CURRENT_APP
Expand Down Expand Up @@ -201,6 +213,9 @@ class DeviceEnum(IntEnum):
#: Determine the current app and get the state from ``dumpsys media_session`` for an Android 13 device
CMD_CURRENT_APP_MEDIA_SESSION_STATE13 = CMD_CURRENT_APP13 + " && " + CMD_MEDIA_SESSION_STATE

#: Determine the current app and get the state from ``dumpsys media_session`` for a Askey STI6130
CMD_CURRENT_APP_MEDIA_SESSION_STATE_ASKEY_STI6130 = CMD_CURRENT_APP_ASKEY_STI6130 + " && " + CMD_MEDIA_SESSION_STATE

#: Determine the current app and get the state from ``dumpsys media_session`` for a Google TV device
CMD_CURRENT_APP_MEDIA_SESSION_STATE_GOOGLE_TV = CMD_CURRENT_APP_GOOGLE_TV + " && " + CMD_MEDIA_SESSION_STATE

Expand Down Expand Up @@ -241,13 +256,16 @@ class DeviceEnum(IntEnum):
CMD_MODEL = "getprop ro.product.model"
CMD_SERIALNO = "getprop ro.serialno"
CMD_VERSION = "getprop ro.build.version.release"
CMD_PRODUCT_ID = "getprop ro.product.vendor.device"

# Commands for getting the MAC address
CMD_MAC_WLAN0 = "ip addr show wlan0 | grep -m 1 ether"
CMD_MAC_ETH0 = "ip addr show eth0 | grep -m 1 ether"

#: The command used for getting the device properties
CMD_DEVICE_PROPERTIES = CMD_MANUFACTURER + " && " + CMD_MODEL + " && " + CMD_SERIALNO + " && " + CMD_VERSION
CMD_DEVICE_PROPERTIES = (
CMD_MANUFACTURER + " && " + CMD_MODEL + " && " + CMD_SERIALNO + " && " + CMD_VERSION + " && " + CMD_PRODUCT_ID
)


# ADB key event codes
Expand Down
1 change: 1 addition & 0 deletions tests/generate_test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"CMD_DEFINE_CURRENT_APP_VARIABLE11",
"CMD_DEFINE_CURRENT_APP_VARIABLE12",
"CMD_DEFINE_CURRENT_APP_VARIABLE13",
"CMD_DEFINE_CURRENT_APP_VARIABLE_ASKEY_STI6130",
"CMD_DEFINE_CURRENT_APP_VARIABLE_GOOGLE_TV",
"CMD_LAUNCH_APP_CONDITION",
"CMD_LAUNCH_APP_CONDITION_FIRETV",
Expand Down
15 changes: 15 additions & 0 deletions tests/test_basetv_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
AFTT
SERIALNO
5.1.1
test123
"""

WIFIMAC_OUTPUT1 = " link/ether ab:cd:ef:gh:ij:kl brd ff:ff:ff:ff:ff:ff"
Expand All @@ -31,12 +32,14 @@
"sw_version": "5.1.1",
"wifimac": "ab:cd:ef:gh:ij:kl",
"ethmac": None,
"product_id": "test123",
}

DEVICE_PROPERTIES_OUTPUT2 = """Amazon
AFTT

5.1.1
test456
"""

DEVICE_PROPERTIES_DICT2 = {
Expand All @@ -46,12 +49,14 @@
"sw_version": "5.1.1",
"wifimac": "ab:cd:ef:gh:ij:kl",
"ethmac": None,
"product_id": "test456",
}

DEVICE_PROPERTIES_OUTPUT3 = """Not Amazon
AFTT
SERIALNO
5.1.1
test678
"""

WIFIMAC_OUTPUT3 = 'Device "wlan0" does not exist.'
Expand All @@ -64,6 +69,7 @@
"sw_version": "5.1.1",
"wifimac": None,
"ethmac": "ab:cd:ef:gh:ij:kl",
"product_id": "test678",
}


Expand All @@ -72,6 +78,7 @@
Chromecast
SERIALNO
10
ccwgtv1
"""

WIFIMAC_GOOGLE = " link/ether ab:cd:ef:gh:ij:kl brd ff:ff:ff:ff:ff:ff"
Expand All @@ -81,6 +88,7 @@
BRAVIA 4K GB
SERIALNO
8.0.0
sonytestproduct
"""

WIFIMAC_SONY = " link/ether 11:22:33:44:55:66 brd ff:ff:ff:ff:ff:ff"
Expand All @@ -93,12 +101,14 @@
"sw_version": "8.0.0",
"wifimac": "11:22:33:44:55:66",
"ethmac": "ab:cd:ef:gh:ij:kl",
"product_id": "sonytestproduct",
}

DEVICE_PROPERTIES_OUTPUT_SHIELD_TV_11 = """NVIDIA
SHIELD Android TV
0123456789012
11
nvshield11
"""

WIFIMAC_SHIELD_TV_11 = " link/ether 11:22:33:44:55:66 brd ff:ff:ff:ff:ff:ff"
Expand All @@ -108,6 +118,7 @@
SHIELD Android TV
0123456789012
12
nvshield12
"""

WIFIMAC_SHIELD_TV_12 = " link/ether 11:22:33:44:55:66 brd ff:ff:ff:ff:ff:ff"
Expand All @@ -117,6 +128,7 @@
SHIELD Android TV
0123456789012
13
nvshield13
"""

WIFIMAC_SHIELD_TV_13 = " link/ether 11:22:33:44:55:66 brd ff:ff:ff:ff:ff:ff"
Expand All @@ -129,6 +141,7 @@
"sw_version": "11",
"wifimac": "11:22:33:44:55:66",
"ethmac": "ab:cd:ef:gh:ij:kl",
"product_id": "nvshield11",
}

DEVICE_PROPERTIES_DICT_SHIELD_TV_12 = {
Expand All @@ -138,6 +151,7 @@
"sw_version": "12",
"wifimac": "11:22:33:44:55:66",
"ethmac": "ab:cd:ef:gh:ij:kl",
"product_id": "nvshield12",
}

DEVICE_PROPERTIES_DICT_SHIELD_TV_13 = {
Expand All @@ -147,6 +161,7 @@
"sw_version": "13",
"wifimac": "11:22:33:44:55:66",
"ethmac": "ab:cd:ef:gh:ij:kl",
"product_id": "nvshield13",
}

INSTALLED_APPS_OUTPUT_1 = """package:org.example.app
Expand Down
15 changes: 14 additions & 1 deletion tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def test_constants(self):
constants.CMD_CURRENT_APP13,
r"CURRENT_APP=$(dumpsys window windows | grep -E -m 1 'imeLayeringTarget|imeInputTarget|imeControlTarget') && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP##* } && echo $CURRENT_APP",
)
# CMD_CURRENT_APP_ASKEY_STI6130
self.assertCommand(
constants.CMD_CURRENT_APP_ASKEY_STI6130,
r"CURRENT_APP=$(dumpsys window windows | grep -E -m 1 'imeLayeringTarget|imeInputTarget|imeControlTarget') && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP##* } && echo $CURRENT_APP ",
)

# CMD_CURRENT_APP_GOOGLE_TV
self.assertCommand(
Expand Down Expand Up @@ -130,6 +135,11 @@ def test_constants(self):
constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE13,
r"CURRENT_APP=$(dumpsys window windows | grep -E -m 1 'imeLayeringTarget|imeInputTarget|imeControlTarget') && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP##* } && echo $CURRENT_APP && dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {'",
)
# CMD_CURRENT_APP_MEDIA_SESSION_STATE_ASKEY_STI6130
self.assertCommand(
constants.CMD_CURRENT_APP_MEDIA_SESSION_STATE_ASKEY_STI6130,
r"CURRENT_APP=$(dumpsys window windows | grep -E -m 1 'imeLayeringTarget|imeInputTarget|imeControlTarget') && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP##* } && echo $CURRENT_APP && dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {'",
)

# CMD_CURRENT_APP_MEDIA_SESSION_STATE_GOOGLE_TV
self.assertCommand(
Expand All @@ -140,7 +150,7 @@ def test_constants(self):
# CMD_DEVICE_PROPERTIES
self.assertCommand(
constants.CMD_DEVICE_PROPERTIES,
r"getprop ro.product.manufacturer && getprop ro.product.model && getprop ro.serialno && getprop ro.build.version.release",
r"getprop ro.product.manufacturer && getprop ro.product.model && getprop ro.serialno && getprop ro.build.version.release && getprop ro.product.vendor.device",
)

# CMD_HDMI_INPUT
Expand Down Expand Up @@ -212,6 +222,9 @@ def test_constants(self):
# CMD_MODEL
self.assertCommand(constants.CMD_MODEL, r"getprop ro.product.model")

# CMD_PRODUCT_ID
self.assertCommand(constants.CMD_PRODUCT_ID, r"getprop ro.product.vendor.device")

# CMD_RUNNING_APPS
self.assertCommand(constants.CMD_RUNNING_APPS, r"ps -A | grep u0_a")

Expand Down
6 changes: 4 additions & 2 deletions tests/test_setup_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .async_wrapper import awaiter


DEVICE_PROPERTIES_OUTPUT1 = "Amazon\n\n\n123"
DEVICE_PROPERTIES_OUTPUT1 = "Amazon\n\n\n123\namazon123"

DEVICE_PROPERTIES_DICT1 = {
"manufacturer": "Amazon",
Expand All @@ -22,9 +22,10 @@
"sw_version": "123",
"wifimac": None,
"ethmac": None,
"product_id": "amazon123",
}

DEVICE_PROPERTIES_OUTPUT2 = "Not Amazon\n\n\n456"
DEVICE_PROPERTIES_OUTPUT2 = "Not Amazon\n\n\n456\nnotamazon456"

DEVICE_PROPERTIES_DICT2 = {
"manufacturer": "Not Amazon",
Expand All @@ -33,6 +34,7 @@
"sw_version": "456",
"wifimac": None,
"ethmac": None,
"product_id": "notamazon456",
}


Expand Down
6 changes: 4 additions & 2 deletions tests/test_setup_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from . import patchers


DEVICE_PROPERTIES_OUTPUT1 = "Amazon\n\n\n123"
DEVICE_PROPERTIES_OUTPUT1 = "Amazon\n\n\n123\namazon123"

DEVICE_PROPERTIES_DICT1 = {
"manufacturer": "Amazon",
Expand All @@ -26,9 +26,10 @@
"sw_version": "123",
"wifimac": None,
"ethmac": None,
"product_id": "amazon123",
}

DEVICE_PROPERTIES_OUTPUT2 = "Not Amazon\n\n\n456"
DEVICE_PROPERTIES_OUTPUT2 = "Not Amazon\n\n\n456\nnotamazon456"

DEVICE_PROPERTIES_DICT2 = {
"manufacturer": "Not Amazon",
Expand All @@ -37,6 +38,7 @@
"sw_version": "456",
"wifimac": None,
"ethmac": None,
"product_id": "notamazon456",
}


Expand Down
Loading