Skip to content
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
20 changes: 20 additions & 0 deletions tests/test_device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ async def test_auth_no_username_or_password(self, client):
)
assert device_manager is not None

@pytest.mark.asyncio
async def test_auth_token_initialized_without_credentials(self, client):
# Regression test for issue #75
# When creating a device manager without credentials, _auth_token should
# still be initialized to None to avoid AttributeError
device_manager = TPLinkDeviceManager(
username=None,
password=None,
prefetch=True, # This is the default that triggered the bug
cache_devices=True,
tplink_cloud_api_host=os.environ.get('TPLINK_KASA_API_URL'),
verbose=False,
term_id=os.environ.get('TPLINK_KASA_TERM_ID')
)
# Should be able to access _auth_token without AttributeError
assert device_manager._auth_token is None
# Should be able to set auth token manually
device_manager.set_auth_token('test_token')
assert device_manager._auth_token == 'test_token'

@pytest.mark.asyncio
async def test_auth_no_username(self, client):
with pytest.raises(ValueError):
Expand Down
1 change: 1 addition & 0 deletions tplinkcloud/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
self._cache_devices = cache_devices
self._cached_devices = None
self._term_id = term_id
self._auth_token = None

self._tplink_api = TPLinkApi(
tplink_cloud_api_host, verbose=self._verbose, term_id=self._term_id)
Expand Down