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

Error when trying to discover new Tapo P110 plug #818

Open
buzo-ffm opened this issue Mar 11, 2024 · 7 comments
Open

Error when trying to discover new Tapo P110 plug #818

buzo-ffm opened this issue Mar 11, 2024 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@buzo-ffm
Copy link

I'm using the latest git version (commit 7507837) and am getting this error message when trying to discover new Tapo P110 plug:

$ kasa --debug discover
Discovering devices on 255.255.255.255 for 5 seconds
DEBUG:kasa.discover:[DISCOVERY] 255.255.255.255 >> {'system': {'get_sysinfo': None}}
DEBUG:kasa.discover:Waiting 5 seconds for responses...
DEBUG:kasa.aestransport:Created AES transport for 192.168.0.1
DEBUG:kasa.discover:[DISCOVERY] 192.168.0.1 << {'result': {'device_id': '3e76c313b903372794a293c412ac6cb9', 'owner': '', 'device_type': 'SMART.TAPOPLUG', 'device_model': 'P110(EU)', 'ip': '192.168.0.1', 'mac': 'A8-42-A1-D4-6D-FF', 'is_support_iot_cloud': True, 'obd_src': 'tplink', 'factory_default': True, 'mgt_encrypt_schm': {'is_support_https': False, 'encrypt_type': 'AES', 'http_port': 80, 'lv': 2}}, 'error_code': 0}
DEBUG:kasa.device:Initializing 192.168.0.1 of type <class 'kasa.smart.smartdevice.SmartDevice'>
DEBUG:kasa.smartprotocol:192.168.0.1 >> '{"method":"component_nego","params":null,"requestID":1216957516567678976,"request_time_milis":1710186881927,"terminal_uuid":"7zc7SQf75Tz9eiHiYwnmDQ=="}'
DEBUG:kasa.aestransport:Will perform handshaking...
DEBUG:kasa.httpclient:Posting to http://192.168.0.1:80/app
DEBUG:kasa.aestransport:Generating keypair
DEBUG:kasa.aestransport:Handshake params: {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXjTPw1aRDtVYxztNrMzpXHN2MClpDz9nB+WsKLJs8ED10i0H4HQVDTY3eZlg4jtTwhxEY1PzDTpWa6RL9cqm52/L7Xsv2n91TxTgIjMtFtIQMJUwQGxh1P8Y3xXd/GEIEAyFrW9TDYNCcszx2hMw1p/YqCp7qoen86Ul+W2UsFQIDAQAB\n-----END PUBLIC KEY-----\n'}
DEBUG:kasa.aestransport:Request {'method': 'handshake', 'params': {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDXjTPw1aRDtVYxztNrMzpXHN2MClpDz9nB+WsKLJs8ED10i0H4HQVDTY3eZlg4jtTwhxEY1PzDTpWa6RL9cqm52/L7Xsv2n91TxTgIjMtFtIQMJUwQGxh1P8Y3xXd/GEIEAyFrW9TDYNCcszx2hMw1p/YqCp7qoen86Ul+W2UsFQIDAQAB\n-----END PUBLIC KEY-----\n'}}
DEBUG:kasa.aestransport:Device responded with: {'error_code': 0, 'result': {'key': 'jZ/hRS++h2mH5+iuftjX5QJm7rqPZG9UZv8q2iOJFYHjkt9GzeL2lKzSp+p8tTnfpRMNMmlbh3o7W+goAL66DybDPBPA2qz0EtYbo8SF1yqx0Wf4OFgjQp7EBFMD8oK18Wsju8BQ3tsaLMyLEJLV4NLo+UBAnmKr2e/ndR6DJtM='}}
DEBUG:kasa.aestransport:Handshake with 192.168.0.1 complete
DEBUG:kasa.httpclient:Posting to http://192.168.0.1:80/app
DEBUG:kasa.aestransport:Will perform handshaking...
DEBUG:kasa.httpclient:Posting to http://192.168.0.1:80/app
DEBUG:kasa.aestransport:Generating keypair
DEBUG:kasa.aestransport:Handshake params: {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMofrBKtki29w2XLOwIiBWQr+sbwiwkyFoO7rh6BGEHdQBJzUL3VzRre3lxervBrOTAC458YDBCzbU6dA4byQtwTcEhczlgxo97GdyV7VOx2Hia5MLIygyK5+7e1F33of88TIxmWH6oDB4I1LmhHj2ItTG8YWsAnL7GunFGqSwqwIDAQAB\n-----END PUBLIC KEY-----\n'}
DEBUG:kasa.aestransport:Request {'method': 'handshake', 'params': {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMofrBKtki29w2XLOwIiBWQr+sbwiwkyFoO7rh6BGEHdQBJzUL3VzRre3lxervBrOTAC458YDBCzbU6dA4byQtwTcEhczlgxo97GdyV7VOx2Hia5MLIygyK5+7e1F33of88TIxmWH6oDB4I1LmhHj2ItTG8YWsAnL7GunFGqSwqwIDAQAB\n-----END PUBLIC KEY-----\n'}}
DEBUG:kasa.aestransport:Device responded with: {'error_code': 0, 'result': {'key': 'YtrYoqoyANmEyFep9ZsU3PniuJX2o3wjOhMFg8F/hKgyNl4QhInR1ydOu459zmFjXbVKpTIQoTI+ONGeuK8W1jOxDHsJs8LLKgPN0LEdNxLwso/Ri5JwBCCSrgkwQZVmt27VZMVeC18josaWO08tbkjBHh8JcRvBf10rURjG1cQ='}}
DEBUG:kasa.aestransport:Handshake with 192.168.0.1 complete
DEBUG:kasa.httpclient:Posting to http://192.168.0.1:80/app
DEBUG:kasa.aestransport:192.168.0.1: logged in with default credentials
DEBUG:kasa.httpclient:Posting to http://192.168.0.1:80/app?token=BDCD710F98DAF10D0F48F30D1D03F30C
DEBUG:kasa.smartprotocol:192.168.0.1 << {'error_code': 0,
 'result': {'component_list': [{'id': 'device', 'ver_code': 2},
                               {'id': 'firmware', 'ver_code': 2},
                               {'id': 'quick_setup', 'ver_code': 3},
                               {'id': 'time', 'ver_code': 1},
                               {'id': 'wireless', 'ver_code': 1},
                               {'id': 'schedule', 'ver_code': 2},
                               {'id': 'countdown', 'ver_code': 2},
                               {'id': 'antitheft', 'ver_code': 1},
                               {'id': 'account', 'ver_code': 1},
                               {'id': 'synchronize', 'ver_code': 1},
                               {'id': 'sunrise_sunset', 'ver_code': 1},
                               {'id': 'led', 'ver_code': 1},
                               {'id': 'cloud_connect', 'ver_code': 1},
                               {'id': 'iot_cloud', 'ver_code': 1},
                               {'id': 'device_local_time', 'ver_code': 1},
                               {'id': 'default_states', 'ver_code': 1},
                               {'id': 'auto_off', 'ver_code': 2},
                               {'id': 'energy_monitoring', 'ver_code': 2},
                               {'id': 'power_protection', 'ver_code': 1}]}}
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.alarmmodule.AlarmModule'> requires alarm
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.autooffmodule.AutoOffModule'> requires auto_off
DEBUG:kasa.smart.smartdevice:Found required auto_off, adding AutoOffModule to modules.
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.battery.BatterySensor'> requires battery_detect
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.brightness.Brightness'> requires brightness
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.childdevicemodule.ChildDeviceModule'> requires child_device
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.cloudmodule.CloudModule'> requires cloud_connect
DEBUG:kasa.smart.smartdevice:Found required cloud_connect, adding CloudModule to modules.
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.devicemodule.DeviceModule'> requires device
DEBUG:kasa.smart.smartdevice:Found required device, adding DeviceModule to modules.
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.energymodule.EnergyModule'> requires energy_monitoring
DEBUG:kasa.smart.smartdevice:Found required energy_monitoring, adding EnergyModule to modules.
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.firmware.Firmware'> requires firmware
DEBUG:kasa.smart.smartdevice:Found required firmware, adding Firmware to modules.
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.humidity.HumiditySensor'> requires humidity
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.ledmodule.LedModule'> requires led
DEBUG:kasa.smart.smartdevice:Found required led, adding LedModule to modules.
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.lighttransitionmodule.LightTransitionModule'> requires on_off_gradually
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.reportmodule.ReportModule'> requires report_mode
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.temperature.TemperatureSensor'> requires temperature
DEBUG:kasa.smart.smartdevice:<class 'kasa.smart.modules.timemodule.TimeModule'> requires time
DEBUG:kasa.smart.smartdevice:Found required time, adding TimeModule to modules.
DEBUG:kasa.smartprotocol:192.168.0.1 multi-request-batch-1 >> '{"method":"multipleRequest","params":{"requests":[{"method":"get_auto_off_config","params":{"start_index":0}},{"method":"get_connect_cloud_state","params":null},{"method":"get_device_info","params":null},{"method":"get_device_usage","params":null},{"method":"get_energy_usage","params":null}]},"requestID":1216957521483403264,"request_time_milis":1710186883099,"terminal_uuid":"7zc7SQf75Tz9eiHiYwnmDQ=="}'
DEBUG:kasa.httpclient:Posting to http://192.168.0.1:80/app?token=BDCD710F98DAF10D0F48F30D1D03F30C
DEBUG:kasa.smartprotocol:192.168.0.1 multi-request-batch-1 << {'error_code': 0,
 'result': {'responses': [{'error_code': 0,
                           'method': 'get_auto_off_config',
                           'result': {'delay_min': 120, 'enable': False}},
                          {'error_code': 0,
                           'method': 'get_connect_cloud_state',
                           'result': {'status': 1}},
                          {'error_code': 0,
                           'method': 'get_device_info',
                           'result': {'auto_off_remain_time': 0,
                                      'auto_off_status': 'off',
                                      'avatar': '',
                                      'default_states': {'state': {},
                                                         'type': 'last_states'},
                                      'device_id': '8022FDE322F00702F3A4512C1664717E220BEF5C',
                                      'device_on': False,
                                      'fw_id': '00000000000000000000000000000000',
                                      'fw_ver': '1.2.3 Build 230425 Rel.142542',
                                      'has_set_location_info': False,
                                      'hw_id': '2FB30EF5BF920C44099401D396C6B55B',
                                      'hw_ver': '1.0',
                                      'ip': '192.168.0.1',
                                      'lang': '',
                                      'latitude': 0,
                                      'longitude': 0,
                                      'mac': 'A8-42-A1-D4-6D-FF',
                                      'model': 'P110',
                                      'nickname': '',
                                      'oem_id': '18BDC6C734AF8407B3EF871EACFCECF5',
                                      'on_time': 0,
                                      'overheated': False,
                                      'power_protection_status': 'normal',
                                      'region': '',
                                      'rssi': -46,
                                      'signal_level': 3,
                                      'specs': '',
                                      'ssid': '',
                                      'time_diff': 0,
                                      'type': 'SMART.TAPOPLUG'}},
                          {'error_code': -1601, 'method': 'get_device_usage'},
                          {'error_code': -1003, 'method': 'get_energy_usage'}]}}
DEBUG:kasa.smartprotocol:192.168.0.1 multi-request-batch-6 >> '{"method":"multipleRequest","params":{"requests":[{"method":"get_current_power","params":null},{"method":"get_auto_update_info","params":null},{"method":"get_latest_fw","params":null},{"method":"get_led_info","params":{"led_rule":null}},{"method":"get_device_time","params":null}]},"requestID":1216957521777004544,"request_time_milis":1710186883169,"terminal_uuid":"7zc7SQf75Tz9eiHiYwnmDQ=="}'
DEBUG:kasa.httpclient:Posting to http://192.168.0.1:80/app?token=BDCD710F98DAF10D0F48F30D1D03F30C
DEBUG:kasa.smartprotocol:192.168.0.1 multi-request-batch-6 << {'error_code': 0,
 'result': {'responses': [{'error_code': 0,
                           'method': 'get_current_power',
                           'result': {'current_power': 0}},
                          {'error_code': 0,
                           'method': 'get_auto_update_info',
                           'result': {'enable': True,
                                      'random_range': 120,
                                      'time': 180}},
                          {'error_code': -1007, 'method': 'get_latest_fw'},
                          {'error_code': 0,
                           'method': 'get_led_info',
                           'result': {'led_rule': 'always',
                                      'led_status': False,
                                      'night_mode': {'end_time': 420,
                                                     'night_mode_type': 'sunrise_sunset',
                                                     'start_time': 1140,
                                                     'sunrise_offset': 0,
                                                     'sunset_offset': 0}}},
                          {'error_code': 0,
                           'method': 'get_device_time',
                           'result': {'region': '',
                                      'time_diff': 0,
                                      'timestamp': 946771833}}]}}
DEBUG:kasa.smart.smartdevice:Got an update: {'components': {'component_list': [{'id': 'device', 'ver_code': 2}, {'id': 'firmware', 'ver_code': 2}, {'id': 'quick_setup', 'ver_code': 3}, {'id': 'time', 'ver_code': 1}, {'id': 'wireless', 'ver_code': 1}, {'id': 'schedule', 'ver_code': 2}, {'id': 'countdown', 'ver_code': 2}, {'id': 'antitheft', 'ver_code': 1}, {'id': 'account', 'ver_code': 1}, {'id': 'synchronize', 'ver_code': 1}, {'id': 'sunrise_sunset', 'ver_code': 1}, {'id': 'led', 'ver_code': 1}, {'id': 'cloud_connect', 'ver_code': 1}, {'id': 'iot_cloud', 'ver_code': 1}, {'id': 'device_local_time', 'ver_code': 1}, {'id': 'default_states', 'ver_code': 1}, {'id': 'auto_off', 'ver_code': 2}, {'id': 'energy_monitoring', 'ver_code': 2}, {'id': 'power_protection', 'ver_code': 1}]}, 'get_auto_off_config': {'enable': False, 'delay_min': 120}, 'get_connect_cloud_state': {'status': 1}, 'get_device_info': {'device_id': '8022FDE322F00702F3A4512C1664717E220BEF5C', 'fw_ver': '1.2.3 Build 230425 Rel.142542', 'hw_ver': '1.0', 'type': 'SMART.TAPOPLUG', 'model': 'P110', 'mac': 'A8-42-A1-D4-6D-FF', 'hw_id': '2FB30EF5BF920C44099401D396C6B55B', 'fw_id': '00000000000000000000000000000000', 'oem_id': '18BDC6C734AF8407B3EF871EACFCECF5', 'ip': '192.168.0.1', 'time_diff': 0, 'ssid': '', 'rssi': -46, 'signal_level': 3, 'auto_off_status': 'off', 'auto_off_remain_time': 0, 'latitude': 0, 'longitude': 0, 'lang': '', 'avatar': '', 'region': '', 'specs': '', 'nickname': '', 'has_set_location_info': False, 'device_on': False, 'on_time': 0, 'default_states': {'type': 'last_states', 'state': {}}, 'overheated': False, 'power_protection_status': 'normal'}, 'get_device_usage': <SmartErrorCode.TIME_ERROR: -1601>, 'get_energy_usage': <SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>, 'get_current_power': {'current_power': 0}, 'get_auto_update_info': {'enable': True, 'time': 180, 'random_range': 120}, 'get_latest_fw': <SmartErrorCode.CLOUD_FAILED_ERROR: -1007>, 'get_led_info': {'night_mode': {'night_mode_type': 'sunrise_sunset', 'start_time': 1140, 'end_time': 420, 'sunrise_offset': 0, 'sunset_offset': 0}, 'led_status': False, 'led_rule': 'always'}, 'get_device_time': {'time_diff': 0, 'timestamp': 946771833, 'region': ''}, 'child_info': {}}
== None - P110 ==
	Host: 192.168.0.1
	Port: 80
	Device state: False
	== Generic information ==
	Time:         2000-01-02 00:10:33+00:00 (tz: {'timezone': 'UTC'}
	Hardware:     1.0
	Software:     1.2.3 Build 230425 Rel.142542
	MAC (rssi):   A8:42:A1:D4:6D:FF (-46)
	Location:     {'latitude': 0.0, 'longitude': 0.0}

	== Device specific information ==
	overheated: False
	signal_level: 3
	SSID: No SSID

	== Features == 
	Device ID (device_id): 8022FDE322F00702F3A4512C1664717E220BEF5C
	State (state): False
	Signal Level (signal_level): 3
	RSSI (rssi): -46
	SSID (ssid): No SSID
	Overheated (overheated): False
	On since (on_since): None
	Auto off enabled (auto_off_enabled): False
	Auto off minutes (auto_off_minutes): 120
	Auto off at (auto_off_at): None
	Cloud connection (cloud_connection): False
Raised error: 'SmartErrorCode' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/bin/kasa", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1205, in __call__
    return anyio.run(self._main, main, args, kwargs, **opts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/anyio/_core/_eventloop.py", line 73, in run
    return async_backend.run(func, args, {}, backend_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2001, in run
    return runner.run(wrapper())
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1989, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1208, in _main
    return await main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1120, in main
    rv = await self.invoke(ctx)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 137, in invoke
    _handle_exception(self._debug, exc)
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 135, in invoke
    return await super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1739, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1485, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 500, in discover
    discovered_devices = await Discover.discover(
                         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/discover.py", line 313, in discover
    await protocol.wait_for_discovery_to_complete()
  File "/usr/lib/python3.11/site-packages/kasa/discover.py", line 108, in wait_for_discovery_to_complete
    await asyncio.gather(*self.callback_tasks)
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 496, in print_discovered
    await ctx.parent.invoke(state)
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 623, in state
    echo(f"\t{feature.name} ({id_}): {feature.value}")
                                      ^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/feature.py", line 51, in value
    return getattr(container, self.attribute_getter)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/smart/modules/energymodule.py", line 56, in current_power
    return self.emeter_realtime.power
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/smart/modules/energymodule.py", line 71, in emeter_realtime
    "power_mw": self.energy.get("current_power"),
                ^^^^^^^^^^^^^^^
AttributeError: 'SmartErrorCode' object has no attribute 'get'
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7c4cfe1c1110>
ERROR:asyncio:Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7c4cfe190590>, 51146.985564726)]']
connector: <aiohttp.connector.TCPConnector object at 0x7c4cfe1c00d0>
@rytilahti rytilahti added the bug Something isn't working label Mar 11, 2024
@rytilahti
Copy link
Member

Thanks for the report, this is a bug that needs to be fixed.

The device is reporting that it supports energy monitoring (causing the creation of internal feature presentations) but returns an error on the relevant calls which causes the error when the tool tries to access the data:

                          {'error_code': -1601, 'method': 'get_device_usage'},
                          {'error_code': -1003, 'method': 'get_energy_usage'}]}}

@rytilahti rytilahti added this to the 0.7.0 milestone Mar 11, 2024
@buzo-ffm
Copy link
Author

Is there anything I can help to debug this?
Does this bug prevent me from provisioning this device?

@rytilahti
Copy link
Member

rytilahti commented Mar 12, 2024

Maybe, as you can see from the known error codes, -1003 is json decode failure, so you could try executing kasa --host <ip> command get_device_usage '{}' to see if that works. But in the end, the library should handle such errors in a more graceful manner, even if changing that specific query would help in your case.

That second error is related to clock not being synced, which is normal when the device hasn't been provisioned, or at least I had similar issues with my plug. These should not prevent provisioning the device though.

@buzo-ffm
Copy link
Author

That does not work (running the latest code from commit d63f43a).

$ kasa --host 192.168.0.1 command get_device_usage '{}'
No --type or --device-family and --encrypt-type defined, discovering for 5 seconds..
Raised error: Error querying device: 192.168.0.1: TIME_ERROR(-1601) for method: get_device_usage (error_code=TIME_ERROR)
Run with --debug enabled to see stacktrace
$ kasa --host 192.168.0.1 --encrypt-type AES command get_device_usage '{}'
No --type or --device-family and --encrypt-type defined, discovering for 5 seconds..
Raised error: Error querying device: 192.168.0.1: TIME_ERROR(-1601) for method: get_device_usage (error_code=TIME_ERROR)
Run with --debug enabled to see stacktrace
$ kasa --host 192.168.0.1 --type plug command get_device_usage '{}'
Raised error: Communication error on None:get_device_usage
Run with --debug enabled to see stacktrace
$ kasa --debug --host 192.168.0.1 --type plug command get_device_usage '{}'
DEBUG:kasa.device:Initializing 192.168.0.1 of type <class 'kasa.iot.iotplug.IotPlug'>
DEBUG:kasa.iot.iotdevice:Adding module <Module Schedule (schedule) for 192.168.0.1>
DEBUG:kasa.iot.iotdevice:Adding module <Module Usage (schedule) for 192.168.0.1>
DEBUG:kasa.iot.iotdevice:Adding module <Module Antitheft (anti_theft) for 192.168.0.1>
DEBUG:kasa.iot.iotdevice:Adding module <Module Time (time) for 192.168.0.1>
DEBUG:kasa.iot.iotdevice:Adding module <Module Cloud (cnCloud) for 192.168.0.1>
DEBUG:kasa.iotprotocol:Unable to query the device: 192.168.0.1, not retrying: Unable to connect to the device: 192.168.0.1:9999: [Errno 111] Connect call failed ('192.168.0.1', 9999)
Raised error: Communication error on None:get_device_usage
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/kasa/xortransport.py", line 129, in send
    await self._connect(self._timeout)
  File "/usr/lib/python3.11/site-packages/kasa/xortransport.py", line 66, in _connect
    self.reader, self.writer = await task
                               ^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/streams.py", line 48, in open_connection
    transport, _ = await loop.create_connection(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1086, in create_connection
    raise exceptions[0]
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1070, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 974, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 638, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/selector_events.py", line 678, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.0.1', 9999)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/kasa/iot/iotdevice.py", line 234, in _query_helper
    response = await self._raw_query(request=request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/device.py", line 184, in _raw_query
    return await self.protocol.query(request=request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/iotprotocol.py", line 43, in query
    return await self._query(request, retry_count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/iotprotocol.py", line 80, in _query
    raise ex
  File "/usr/lib/python3.11/site-packages/kasa/iotprotocol.py", line 48, in _query
    return await self._execute_query(request, retry)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/iotprotocol.py", line 86, in _execute_query
    return await self._transport.send(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/xortransport.py", line 132, in send
    raise KasaException(
kasa.exceptions.KasaException: Unable to connect to the device: 192.168.0.1:9999: [Errno 111] Connect call failed ('192.168.0.1', 9999)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/bin/kasa", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1205, in __call__
    return anyio.run(self._main, main, args, kwargs, **opts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/anyio/_core/_eventloop.py", line 73, in run
    return async_backend.run(func, args, {}, backend_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2001, in run
    return runner.run(wrapper())
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1989, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1208, in _main
    return await main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1120, in main
    rv = await self.invoke(ctx)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 137, in invoke
    _handle_exception(self._debug, exc)
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 135, in invoke
    return await super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1739, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 1485, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/cli.py", line 700, in cmd_command
    res = await dev._query_helper(module, command, parameters)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/kasa/iot/iotdevice.py", line 236, in _query_helper
    raise KasaException(f"Communication error on {target}:{cmd}") from ex
kasa.exceptions.KasaException: Communication error on None:get_device_usage

@buzo-ffm
Copy link
Author

If you have any patch I could try, please let me know.

@rytilahti
Copy link
Member

You cannot use --type plug on tapo devices, so if you leave that out it should perform discovery for the protocol parameters and get you one step forward.

You could also try to set the device time manually (see home-assistant/core#113196 (comment)) to avoid the error altogether.

One downside of local provisioning is that you cannot let the device connect to the internet, or it will stop working until the connection gets cut off again.

@sdb9696
Copy link
Collaborator

sdb9696 commented May 1, 2024

I think all these errors are related to the same TIME issue due to the device not being provisioned/connected (including the {'error_code': -1007, 'method': 'get_latest_fw'}, which is a CLOUD_FAILED_ERROR.

We've confirmed support for these methods with the same hardware and firmware versions: https://github.com/python-kasa/python-kasa/blob/master/kasa/tests/fixtures/smart/P110(EU)_1.0_1.2.3.json so I don't think this is a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants