1414
1515import asyncio
1616import os
17- import sys
1817
18+ import kasa
1919from kasa import Credentials , Device , DeviceConfig , DeviceConnectionParameters , DeviceEncryptionType , DeviceFamily
20+ from packaging .version import parse
21+
22+
23+ def _using_old_kasa_api () -> bool :
24+ target_kasa_version = parse ("0.10.0" )
25+ current_kasa_version = parse (kasa .__version__ )
26+ return current_kasa_version < target_kasa_version
2027
2128
2229def _get_credentials () -> Credentials :
@@ -28,10 +35,8 @@ def _get_credentials() -> Credentials:
2835
2936
3037def _get_connection_type () -> DeviceConnectionParameters :
31- # Somewhere between python-kasa 0.7.7 and 0.10.2 the API changed
32- # Labgrid on Python <= 3.10 uses python-kasa 0.7.7
33- # Labgrid on Python >= 3.11 uses python-kasa 0.10.2
34- if sys .version_info < (3 , 11 ):
38+ # API changed between versions 0.9.1 and 0.10.0 of python-kasa
39+ if _using_old_kasa_api ():
3540 return DeviceConnectionParameters (
3641 device_family = DeviceFamily .SmartTapoPlug ,
3742 encryption_type = DeviceEncryptionType .Klap ,
@@ -49,10 +54,10 @@ def _get_connection_type() -> DeviceConnectionParameters:
4954
5055def _get_device_config (host : str ) -> DeviceConfig :
5156 # Same as with `_get_connection_type` - python-kasa API changed
52- if sys . version_info < ( 3 , 11 ):
57+ if _using_old_kasa_api ( ):
5358 return DeviceConfig (
5459 host = host , credentials = _get_credentials (), connection_type = _get_connection_type (), uses_http = True
55- )
60+ ) # type: ignore[call-arg]
5661 return DeviceConfig (
5762 host = host , credentials = _get_credentials (), connection_type = _get_connection_type ()
5863 )
0 commit comments