@@ -69,7 +69,14 @@ class BaseTV(object): # pylint: disable=too-few-public-methods
6969 DEVICE_ENUM = constants .DeviceEnum .BASETV
7070
7171 def __init__ (
72- self , adb , host , port = 5555 , adbkey = "" , adb_server_ip = "" , adb_server_port = 5037 , state_detection_rules = None
72+ self ,
73+ adb ,
74+ host ,
75+ port = 5555 ,
76+ adbkey = "" ,
77+ adb_server_ip = "" ,
78+ adb_server_port = 5037 ,
79+ state_detection_rules = None ,
7380 ):
7481 self ._adb = adb
7582 self .host = host
@@ -131,6 +138,14 @@ def _cmd_audio_state(self):
131138 # Is this an Android 11 device?
132139 if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "11" :
133140 return constants .CMD_AUDIO_STATE11
141+
142+ # Is this an Android 12 device?
143+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "12" :
144+ return constants .CMD_AUDIO_STATE11
145+
146+ # Is this an Android 13 device?
147+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "13" :
148+ return constants .CMD_AUDIO_STATE11
134149 return constants .CMD_AUDIO_STATE
135150
136151 def _cmd_current_app (self ):
@@ -157,6 +172,14 @@ def _cmd_current_app(self):
157172 if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "11" :
158173 return constants .CMD_CURRENT_APP11
159174
175+ # Is this an Android 12 device?
176+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "12" :
177+ return constants .CMD_CURRENT_APP12
178+
179+ # Is this an Android 13 device?
180+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "13" :
181+ return constants .CMD_CURRENT_APP13
182+
160183 return constants .CMD_CURRENT_APP
161184
162185 def _cmd_current_app_media_session_state (self ):
@@ -183,6 +206,14 @@ def _cmd_current_app_media_session_state(self):
183206 if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "11" :
184207 return constants .CMD_CURRENT_APP_MEDIA_SESSION_STATE11
185208
209+ # Is this an Android 12 device?
210+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "12" :
211+ return constants .CMD_CURRENT_APP_MEDIA_SESSION_STATE12
212+
213+ # Is this an Android 13 device?
214+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "13" :
215+ return constants .CMD_CURRENT_APP_MEDIA_SESSION_STATE13
216+
186217 return constants .CMD_CURRENT_APP_MEDIA_SESSION_STATE
187218
188219 def _cmd_hdmi_input (self ):
@@ -201,8 +232,39 @@ def _cmd_hdmi_input(self):
201232 if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "11" :
202233 return constants .CMD_HDMI_INPUT11
203234
235+ # Is this an Android 12 device?
236+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "12" :
237+ return constants .CMD_HDMI_INPUT11
238+
239+ # Is this an Android 13 device?
240+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "13" :
241+ return constants .CMD_HDMI_INPUT11
242+
204243 return constants .CMD_HDMI_INPUT
205244
245+ def _cmd_volume_set (self ):
246+ """Get the command used to set volume for this device.
247+
248+ Returns
249+ -------
250+ str
251+ The device-specific ADB shell command used to set volume
252+
253+ """
254+ # Is this an Android 11 device?
255+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "11" :
256+ return constants .CMD_VOLUME_SET_COMMAND11
257+
258+ # Is this an Android 12 device?
259+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "12" :
260+ return constants .CMD_VOLUME_SET_COMMAND11
261+
262+ # Is this an Android 13 device?
263+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "13" :
264+ return constants .CMD_VOLUME_SET_COMMAND11
265+
266+ return constants .CMD_VOLUME_SET_COMMAND
267+
206268 def _cmd_launch_app (self , app ):
207269 """Get the command to launch the specified app for this device.
208270
@@ -235,6 +297,14 @@ def _cmd_launch_app(self, app):
235297 if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "11" :
236298 return constants .CMD_LAUNCH_APP11 .format (app )
237299
300+ # Is this an Android 12 device?
301+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "12" :
302+ return constants .CMD_LAUNCH_APP12 .format (app )
303+
304+ # Is this an Android 13 device?
305+ if self .DEVICE_ENUM == constants .DeviceEnum .ANDROIDTV and self .device_properties .get ("sw_version" , "" ) == "13" :
306+ return constants .CMD_LAUNCH_APP13 .format (app )
307+
238308 return constants .CMD_LAUNCH_APP .format (app )
239309
240310 def _cmd_running_apps (self ):
@@ -339,7 +409,12 @@ def _parse_device_properties(self, properties):
339409 ``'serialno'``, ``'manufacturer'``, ``'model'``, and ``'sw_version'``
340410
341411 """
342- _LOGGER .debug ("%s:%d `get_device_properties` response: %s" , self .host , self .port , properties )
412+ _LOGGER .debug (
413+ "%s:%d `get_device_properties` response: %s" ,
414+ self .host ,
415+ self .port ,
416+ properties ,
417+ )
343418
344419 if not properties :
345420 self .device_properties = {}
@@ -353,7 +428,12 @@ def _parse_device_properties(self, properties):
353428 manufacturer , model , serialno , version = lines
354429
355430 if not serialno .strip ():
356- _LOGGER .warning ("Could not obtain serialno for %s:%d, got: '%s'" , self .host , self .port , serialno )
431+ _LOGGER .warning (
432+ "Could not obtain serialno for %s:%d, got: '%s'" ,
433+ self .host ,
434+ self .port ,
435+ serialno ,
436+ )
357437 serialno = None
358438
359439 self .device_properties = {
@@ -393,7 +473,11 @@ def _parse_mac_address(mac_response):
393473 # #
394474 # ======================================================================= #
395475 def _custom_state_detection (
396- self , current_app = None , media_session_state = None , wake_lock_size = None , audio_state = None
476+ self ,
477+ current_app = None ,
478+ media_session_state = None ,
479+ wake_lock_size = None ,
480+ audio_state = None ,
397481 ):
398482 """Use the rules in ``self._state_detection_rules`` to determine the state.
399483
@@ -670,7 +754,11 @@ def _parse_stream_music(stream_music_raw):
670754 if not stream_music_raw :
671755 return None
672756
673- matches = re .findall (constants .STREAM_MUSIC_REGEX_PATTERN , stream_music_raw , re .DOTALL | re .MULTILINE )
757+ matches = re .findall (
758+ constants .STREAM_MUSIC_REGEX_PATTERN ,
759+ stream_music_raw ,
760+ re .DOTALL | re .MULTILINE ,
761+ )
674762 if matches :
675763 return matches [0 ]
676764
@@ -747,15 +835,21 @@ def _volume(self, stream_music, audio_output_device):
747835 return None
748836
749837 if not self .max_volume :
750- max_volume_matches = re .findall (constants .MAX_VOLUME_REGEX_PATTERN , stream_music , re .DOTALL | re .MULTILINE )
838+ max_volume_matches = re .findall (
839+ constants .MAX_VOLUME_REGEX_PATTERN ,
840+ stream_music ,
841+ re .DOTALL | re .MULTILINE ,
842+ )
751843 if max_volume_matches :
752844 self .max_volume = float (max_volume_matches [0 ])
753845
754846 if not audio_output_device :
755847 return None
756848
757849 volume_matches = re .findall (
758- audio_output_device + constants .VOLUME_REGEX_PATTERN , stream_music , re .DOTALL | re .MULTILINE
850+ audio_output_device + constants .VOLUME_REGEX_PATTERN ,
851+ stream_music ,
852+ re .DOTALL | re .MULTILINE ,
759853 )
760854 if volume_matches :
761855 return int (volume_matches [0 ])
@@ -899,7 +993,9 @@ def state_detection_rules_validator(rules, exc=KeyError):
899993 if not isinstance (value , constants .VALID_PROPERTIES_TYPES [prop ]):
900994 raise exc (
901995 "Conditional value for property '{0}' must be of type {1}, not {2}" .format (
902- prop , constants .VALID_PROPERTIES_TYPES [prop ].__name__ , type (value ).__name__
996+ prop ,
997+ constants .VALID_PROPERTIES_TYPES [prop ].__name__ ,
998+ type (value ).__name__ ,
903999 )
9041000 )
9051001
0 commit comments