Skip to content

Tapo P110M: Error processing Energy for device, module will be unavailable: get_energy_usage for Energy #1243

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

Closed
a81j opened this issue Nov 11, 2024 · 30 comments · Fixed by #1244 or #1245
Labels
bug Something isn't working

Comments

@a81j
Copy link

a81j commented Nov 11, 2024

Tapo P110M AU & Home Assistant 2024.11.1

On/off works in Home Assistant but energy consumption sensors say Unavailable.

Fixture file attached.
P110M(AU)_1.0_1.2.3.json

Kasa 0.7.7:

kasa --username <u>  --password <p> --host <ip> feature

Discovering device redacted for 10 seconds
WARNING:kasa.smart.smartdevice:Error processing Energy for device 10.0.1.115, module will be unavailable: get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)
== Primary features ==
State (state): True
Unable to read value (current_consumption): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))

== Information ==
Signal Level (signal_level): 2
Auto off at (auto_off_at): None
Cloud connection (cloud_connection): False
Unable to read value (consumption_today): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Unable to read value (consumption_this_month): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Update available (update_available): None
Check latest firmware (check_latest_firmware): <Action>

== Configuration ==
Auto off enabled (auto_off_enabled): False
Auto off in (auto_off_minutes): 120 min (range: 0-65536)
Auto update enabled (auto_update_enabled): False
LED (led): True

== Debug ==
Device ID (device_id): redacted
RSSI (rssi): -58 dBm
SSID (ssid): redacted
On since (on_since): 2000-01-02 11:12:02+11:00
Reboot (reboot): <Action>
Current firmware version (current_firmware_version): 1.2.3 Build 240617 Rel.153525
Available firmware version (available_firmware_version): None
Device time (device_time): 2000-01-08 07:49:26+11:00

@rytilahti
Copy link
Member

Hi & thanks for the report and the fixture! Could you try if #1245 fixes the issue?

@rytilahti rytilahti added the bug Something isn't working label Nov 11, 2024
@a81j
Copy link
Author

a81j commented Nov 12, 2024

I'm not sure this is running the fixed branch, but this is what I tried:

git clone https://github.com/python-kasa/python-kasa.git
cd python-kasa
git checkout fix/p110m_emeter
uv sync --all-extras
uv run kasa  --username redacted  --password redacted--host redacted feature
Discovering device redacted for 10 seconds
WARNING  Error processing Energy for device redacted, module will be unavailable:             smartdevice.py:224
         get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)                                          
== Primary features ==
State (state): True
Unable to read value (current_consumption): ('Module update error', 
DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))

== Information ==
Signal Level (signal_level): 2
Auto off at (auto_off_at): None
Cloud connection (cloud_connection): False
Unable to read value (consumption_today): ('Module update error', 
DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Unable to read value (consumption_this_month): ('Module update error', 
DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Update available (update_available): None
Check latest firmware (check_latest_firmware): <Action>

== Configuration ==
Auto off enabled (auto_off_enabled): False
Auto off in (auto_off_minutes): 120 min (range: 0-65536)
Auto update enabled (auto_update_enabled): False
LED (led): True

== Debug ==
Device ID (device_id): redacted
RSSI (rssi): -55 dBm
SSID (ssid): redacted
On since (on_since): 2000-01-02 11:12:02+11:00
Reboot (reboot): <Action>
Current firmware version (current_firmware_version): 1.2.3 Build 240617 Rel.153525
Available firmware version (available_firmware_version): None
Device time (device_time): 2000-01-09 06:18:10+11:00`

@MrEbbinghaus
Copy link

@a81j Can you please run the feature command with --debug?

kasa .... --debug feature

Furthermore, could you check if this also fails?
kasa .... --debug command get_energy_usage

feature runs multiple requests at once, which had issues in the past: #1027

command get_energy_usage just requests the one thing that fails.


The --debug command logs the queries sent to the device, so you can check what request causes the issue.

Example

DEBUG:kasa.smartprotocol:192.168.178.149 >> '{"method":"get_energy_usage","request_time_milis":1731593717136,"terminal_uuid":"TVHjVu8VSP1i5XUMgUP+Pg=="}'
DEBUG:kasa.smartprotocol:192.168.178.149 << {'error_code': 0,
 'result': {'current_power': 5330,
            'electricity_charge': [0, 0, 0],
            'local_time': '2024-11-14 15:15:09',
            'month_energy': 3712,
            'month_runtime': 7885,
            'today_energy': 78,
            'today_runtime': 466}}

@donleistman
Copy link

donleistman commented Nov 15, 2024

Hi, I think I may be encountering the same issue.

Here's what I get when running `kasa ... --host `
Discovering device 10.0.50.16 for 10 seconds
WARNING:kasa.smart.smartdevice:Error processing Energy for device 10.0.50.16, module will be unavailable: get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)
== None - EP25 ==
Host: 10.0.50.16
Port: 80
Device state: True
Time:         2000-01-02 00:18:43+00:00 (tz: UTC)
Hardware:     2.6
Software:     1.0.2 Build 231108 Rel.163012
MAC (rssi):   24:2F:D0:24:AA:A6 (-44)

== Primary features ==
State (state): True
Unable to read value (current_consumption): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))

== Information ==
Signal Level (signal_level): 3
Overheated (overheated): False
Auto off at (auto_off_at): None
Cloud connection (cloud_connection): False
Unable to read value (consumption_today): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Unable to read value (consumption_this_month): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Update available (update_available): None
Check latest firmware (check_latest_firmware): <Action>

== Configuration ==
Auto off enabled (auto_off_enabled): False
Auto off in (auto_off_minutes): 120 min (range: 0-65536)
Auto update enabled (auto_update_enabled): False
LED (led): False

== Debug ==
Device ID (device_id): 803AB65AFCF2ADAE6BB5120537EEF97B22560110
RSSI (rssi): -44 dBm
SSID (ssid): CHOAM-iot
On since (on_since): 2000-01-02 00:02:13+00:00
Reboot (reboot): <Action>
Current firmware version (current_firmware_version): 1.0.2 Build 231108 Rel.163012
Available firmware version (available_firmware_version): None
Device time (device_time): 2000-01-02 00:18:43+00:00
Here's what I get when I try `kasa .... --debug command get_energy_usage`
Discovering device 10.0.50.16 for 10 seconds
DEBUG:kasa.discover:[DISCOVERY] 10.0.50.16 >> {'system': {'get_sysinfo': {}}}
DEBUG:kasa.discover:Waiting a total of 10 seconds for responses...
DEBUG:kasa.aestransport:Created AES transport for 10.0.50.16
DEBUG:kasa.discover:[DISCOVERY] 10.0.50.16 << {'error_code': 0,
 'result': {'device_id': 'REDACTED_a0948946bc6e5f059060143',
            'device_model': 'EP25(US)',
            'device_type': 'SMART.KASAPLUG',
            'factory_default': False,
            'ip': '10.0.50.16',
            'is_support_iot_cloud': True,
            'mac': '24-2F-D0-00-00-00',
            'mgt_encrypt_schm': {'encrypt_type': 'AES',
                                 'http_port': 80,
                                 'is_support_https': False,
                                 'lv': 2},
            'obd_src': 'tplink',
            'owner': 'REDACTED_172639E770A6AACB78A3ED4'}}
DEBUG:kasa.device:Initializing 10.0.50.16 of type <class 'kasa.smart.smartdevice.SmartDevice'>
DEBUG:kasa.smartprotocol:10.0.50.16 >> '{"method":"get_energy_usage","request_time_milis":1731645851018,"terminal_uuid":"R6OVeYb63RY+7JCF7fDKeQ=="}'
DEBUG:kasa.aestransport:Will perform handshaking...
DEBUG:kasa.httpclient:Posting to http://10.0.50.16/app
DEBUG:kasa.aestransport:Generating keypair
DEBUG:kasa.aestransport:Handshake request: {'method': 'handshake', 'params': {'key': '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMUVQMmNTH/FfcEq6viMynOXd1d0UmRmSNXntaxTzG3dpPW09oCz1TcBsLJ3Vp8p0UbB01/35nMthlefBBp4iWOQy6opwCxxeoJCJHyDXjXm18S4euK8E/lrpJw9QsisaY6r/x6YTjDY4VLcCfnRM0zepfK7gypOrbfS5gt/sZMQIDAQAB\n-----END PUBLIC KEY-----\n'}}
DEBUG:kasa.aestransport:Device responded with: {'error_code': 0, 'result': {'key': 'aN2cC1omia2Qtb9hnCUHV8fT9CQS3TMJi4lkh4OAh8mkDItmZO11Addtw4dkW97ktpzWdEvpLg88uWlmXciX59AjodWjFCZVylwpHSp4xMD+6ZEIrIbViPFS07gz+n3FtiCJwWHDDgx5B2Ht+VsQaDbv4dvUq/AhY3tytR3jWEM='}}
DEBUG:kasa.aestransport:Handshake with 10.0.50.16 complete
DEBUG:kasa.httpclient:Posting to http://10.0.50.16/app
DEBUG:kasa.aestransport:10.0.50.16: logged in with provided credentials
DEBUG:kasa.httpclient:Posting to http://10.0.50.16/app?token=682E6FC3F5736FC1283D6DC1E6536DC0
DEBUG:kasa.smartprotocol:10.0.50.16 << {'error_code': -1003}
DEBUG:kasa.smartprotocol:Unable to query the device: 10.0.50.16, not retrying: Error querying device: 10.0.50.16: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR)
Raised error: Error querying device: 10.0.50.16: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR)
Traceback (most recent call last):
  File "/Users/don/Documents/repos/kasa_env/bin/kasa", line 8, in <module>
    sys.exit(cli())
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/asyncclick/core.py", line 1205, in __call__
    return anyio.run(self._main, main, args, kwargs, **opts)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/anyio/_core/_eventloop.py", line 74, in run
    return async_backend.run(func, args, {}, backend_options)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 2284, in run
    return runner.run(wrapper())
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 210, in run
    return self._loop.run_until_complete(task)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 2272, in wrapper
    return await func(*args)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/asyncclick/core.py", line 1208, in _main
    return await main(*args, **kwargs)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/asyncclick/core.py", line 1120, in main
    rv = await self.invoke(ctx)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/cli/common.py", line 231, in invoke
    _handle_exception(self._debug, exc)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/cli/common.py", line 229, in invoke
    return await super().invoke(ctx)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/asyncclick/core.py", line 1739, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/asyncclick/core.py", line 1485, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/cli/common.py", line 129, in wrapper
    return await ctx.invoke(wrapped_function, dev, *args, **kwargs)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/cli/main.py", line 446, in cmd_command
    res = await dev._query_helper(command, parameters)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/smart/smartdevice.py", line 592, in _query_helper
    res = await self.protocol.query({method: params})
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/smartprotocol.py", line 89, in query
    return await self._query(request, retry_count)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/smartprotocol.py", line 150, in _query
    raise ex
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/smartprotocol.py", line 94, in _query
    return await self._execute_query(
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/smartprotocol.py", line 281, in _execute_query
    self._handle_response_error_code(response_data, smart_method)
  File "/Users/don/Documents/repos/kasa_env/lib/python3.9/site-packages/kasa/smartprotocol.py", line 354, in _handle_response_error_code
    raise DeviceError(msg, error_code=error_code)
kasa.exceptions.DeviceError: Error querying device: 10.0.50.16: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR)
This is what I'm seeing in Home Assistant: Screenshot 2024-11-14 at 11 48 40 PM

Happy to provide anything else that might be helpful.

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 15, 2024

Hi, could you try with the latest commit to #1245. I've pushed an experimental fix.

@MrEbbinghaus
Copy link

MrEbbinghaus commented Nov 15, 2024

Funny. Today I had the same issue after I had to unplug my P110M because apparently the relay got stuck.

Then I noticed, that the clock had reset, because the device was without power.
Syncing the clock fixed the issue.

@a81j @donleistman I see that the clocks on your devices are also back in the year 2000.

Run kasa --host xxx.xxx.xxx.xxx time sync to set the time.


@sdb9696 @rytilahti At first I thought that the wrong time would break the encrypted communication, but other commands clearly work.

My next guess is that the device needs the time for the stats and that fails because the clock is now in the past. This would explain, why only this one command fails.

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 15, 2024

Did you test today with the latest commit to 1245?

@MrEbbinghaus
Copy link

No. I used the 0.7.7 release.

Setting the time back manually doesn't seem to break it. (for the release version and for af8e648)

kasa --host 192.168.178.34 time set 2000 01 01 01 00
Discovering device 192.168.178.34 for 10 seconds
Old time: 2024-11-15 16:02:06+01:00 (CET)
New time: 2000-01-01 01:00:00+01:00 (CET)kasa --host 192.168.178.34 command get_energy_usage
Discovering device 192.168.178.34 for 10 seconds
{"get_energy_usage": {"today_runtime": 0, "month_runtime": 0, "today_energy": 0, "month_energy": 0, "local_time": "2000-01-01 01:00:08", "electricity_charge": [0, 0, 0], "current_power": 5283}}uv run kasa --host 192.168.178.34 command get_energy_usage
Discovering device 192.168.178.34 for 10 seconds
{"get_energy_usage": {"today_runtime": 0, "month_runtime": 0, "today_energy": 0, "month_energy": 0, "local_time": "2000-01-01 01:00:22", "electricity_charge": [0, 0, 0], "current_power": 5457}}

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 15, 2024

No. I used the 0.7.7 release.

@MrEbbinghaus, were you definitely getting the same error beforehand? i.e. JSON_DECODE_FAIL_ERROR

@MrEbbinghaus
Copy link

MrEbbinghaus commented Nov 15, 2024

@sdb9696 Yes, see my console log:

console log
kasa
No host name given, trying discovery..
Discovering devices on 255.255.255.255 for 10 seconds
WARNING:kasa.smart.smartdevice:Error processing Energy for device 192.168.178.34, module will be unavailable: get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)
== Tapo1 - P110M ==
Host: 192.168.178.34
Port: 80
Device state: True
Time:         2000-01-02 01:04:57+01:00 (tz: CET)
Hardware:     1.0
Software:     1.2.3 Build 240617 Rel.153525
MAC (rssi):   REDACTED (-34)

== Primary features ==
State (state): True
Unable to read value (current_consumption): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))

== Information ==
Signal Level (signal_level): 3
Auto off at (auto_off_at): None
Cloud connection (cloud_connection): False
Unable to read value (consumption_today): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Unable to read value (consumption_this_month): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Update available (update_available): None
Check latest firmware (check_latest_firmware): <Action>

== Configuration ==
Auto off enabled (auto_off_enabled): False
Auto off in (auto_off_minutes): 120 min (range: 0-65536)
Auto update enabled (auto_update_enabled): False
LED (led): True

== Debug ==
Device ID (device_id): REDACTED
RSSI (rssi): -34 dBm
SSID (ssid): REDACTED
On since (on_since): 2000-01-02 01:02:26+01:00
Reboot (reboot): <Action>
Current firmware version (current_firmware_version): 1.2.3 Build 240617 Rel.153525
Available firmware version (available_firmware_version): None
Device time (device_time): 2000-01-02 01:04:57+01:00

Found 1 deviceskasa --host 192.168.178.34 time sync
Discovering device 192.168.178.34 for 10 seconds
WARNING:kasa.smart.smartdevice:Error processing Energy for device 192.168.178.34, module will be unavailable: get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)
Old time: 2000-01-02 01:05:33+01:00 (CET)
New time: 2024-11-15 14:58:28+01:00 (CET)kasa
No host name given, trying discovery..
Discovering devices on 255.255.255.255 for 10 seconds
== Tapo1 - P110M ==
Host: 192.168.178.34
Port: 80
Device state: True
Time:         2024-11-15 14:58:33+01:00 (tz: CET)
Hardware:     1.0
Software:     1.2.3 Build 240617 Rel.153525
MAC (rssi):   REDACTED (-34)

== Primary features ==
State (state): True
Current consumption (current_consumption): 16.1 W

== Information ==
Signal Level (signal_level): 3
Auto off at (auto_off_at): None
Cloud connection (cloud_connection): False
Today's consumption (consumption_today): 0.063 kWh
This month's consumption (consumption_this_month): 3.928 kWh
Update available (update_available): None
Check latest firmware (check_latest_firmware): <Action>

== Configuration ==
Auto off enabled (auto_off_enabled): False
Auto off in (auto_off_minutes): 120 min (range: 0-65536)
Auto update enabled (auto_update_enabled): False
LED (led): True

== Debug ==
Device ID (device_id): REDACTED
RSSI (rssi): -34 dBm
SSID (ssid): REDACTED
On since (on_since): 2024-11-15 14:55:21+01:00
Reboot (reboot): <Action>
Current firmware version (current_firmware_version): 1.2.3 Build 240617 Rel.153525
Available firmware version (available_firmware_version): None
Device time (device_time): 2024-11-15 14:58:33+01:00

Found 1 devices

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 15, 2024

Cool thanks.

Would you be able to test the PR with the device time set wrong again to see if the {} avoids the JSON_DECODE_FAIL even if the time is wrong?

uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa --host <etc and any other options>

@donleistman
Copy link

@MrEbbinghaus Syncing the clock fixed my issue, thanks! I had synced it previously, but it looks like it was reset when I moved the plug. Is it necessary to sync the clock whenever the device loses power?

@a81j
Copy link
Author

a81j commented Nov 17, 2024

Cool thanks.

Would you be able to test the PR with the device time set wrong again to see if the {} avoids the JSON_DECODE_FAIL even if the time is wrong?

uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa --host <etc and any other options>

The official app works just fine with the time not set. I have NTP blocked on this subnet, so it would be great if it would work without it too.

I have tried the latest with the same errors:

debug --feature:

uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa  --username redacted  --password redacted --host 10.0.1.2 --debug  feature
 Updated https://github.com/python-kasa/python-kasa.git (af8e648)
Discovering device 10.0.1.2 for 10 seconds
DEBUG:kasa.discover:[DISCOVERY] 10.0.1.2 >> {'system': {'get_sysinfo': {}}}
DEBUG:kasa.discover:Waiting a total of 10 seconds for responses...
DEBUG:kasa.klaptransport:Created KLAP transport for 10.0.1.2
DEBUG:kasa.discover:[DISCOVERY] 10.0.1.2 << {'error_code': 0,
 'result': {'device_id': 'redacted',
            'device_model': 'P110M(AU)',
            'device_type': 'SMART.TAPOPLUG',
            'factory_default': False,
            'ip': '10.0.1.2',
            'is_support_iot_cloud': True,
            'mac': 'F0-09-0D-00-00-00',
            'mgt_encrypt_schm': {'encrypt_type': 'KLAP',
                                 'http_port': 80,
                                 'is_support_https': False,
                                 'lv': 2},
            'obd_src': 'tplink',
            'owner': 'REDACTED_14252709E4C2C1AED6D6E5F',
            'protocol_version': 1}}
DEBUG:kasa.device:Initializing 10.0.1.2 of type <class 'kasa.smart.smartdevice.SmartDevice'>
DEBUG:kasa.smartprotocol:10.0.1.2 multi-request-batch-1-of-1 >> '{"method":"multipleRequest","request_time_milis":1731836979145,"terminal_uuid":"DR/K8KRIbCdJEYmleeeK3A==","params":{"requests":[{"method":"component_nego"},{"method":"get_device_info"},{"method":"get_connect_cloud_state"}]}}'
DEBUG:kasa.klaptransport:Starting handshake with 10.0.1.2
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/handshake1
DEBUG:kasa.klaptransport:Handshake1 posted at 2024-11-17 20:49:39.159362. Host is 10.0.1.2, Response status is 200, Request was ba00de73d3b40c1e9ce707e2cc531aeb
DEBUG:kasa.klaptransport:Handshake1 success at 2024-11-17 20:49:39.159451. Host is 10.0.1.2, Server remote_seed is: 10669461c60d1562ade69662c6531663, server hash is: edbc22227d9b6912687f6ecc5b7cc30013fcbb04f72c92049e576723ceabf0ec
DEBUG:kasa.klaptransport:handshake1 hashes match with expected credentials
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/handshake2
DEBUG:kasa.klaptransport:Handshake2 posted 2024-11-17 20:49:39.166244. Host is 10.0.1.2, Response status is 200, Request was 652af77d2da908a8cea1db1b9b7d709839e5ac949390a3154313961276cf63c0
DEBUG:kasa.klaptransport:Handshake with 10.0.1.2 complete
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/request
DEBUG:kasa.klaptransport:Device 10.0.1.2 query posted Host is 10.0.1.2, Sequence is -1490096695, Response status is 200, Request was {"method":"multipleRequest","request_time_milis":1731836979145,"terminal_uuid":"DR/K8KRIbCdJEYmleeeK3A==","params":{"requests":[{"method":"component_nego"},{"method":"get_device_info"},{"method":"get_connect_cloud_state"}]}}
DEBUG:kasa.klaptransport:Device 10.0.1.2 query response received
DEBUG:kasa.smartprotocol:10.0.1.2 multi-request-batch-1-of-1 << {'error_code': 0,
 'result': {'responses': [{'error_code': 0,
                           'method': 'component_nego',
                           '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': 'localSmart',
                                                          'ver_code': 1},
                                                         {'id': 'energy_monitoring',
                                                          'ver_code': 2},
                                                         {'id': 'power_protection',
                                                          'ver_code': 1},
                                                         {'id': 'charging_protection',
                                                          'ver_code': 2},
                                                         {'id': 'matter',
                                                          'ver_code': 2},
                                                         {'id': 'current_protection',
                                                          'ver_code': 1}]}},
                          {'error_code': 0,
                           'method': 'get_device_info',
                           'result': {'auto_off_remain_time': 0,
                                      'auto_off_status': 'off',
                                      'avatar': 'plug',
                                      'charging_status': 'normal',
                                      'default_states': {'state': {},
                                                         'type': 'last_states'},
                                      'device_id': 'REDACTED_4233F584FA8A442C95CFF922300F272',
                                      'device_on': True,
                                      'fw_id': '00000000000000000000000000000000',
                                      'fw_ver': '1.2.3 Build 240617 Rel.153525',
                                      'has_set_location_info': False,
                                      'hw_id': 'B675F6FC1F9EE35C951B7E88DBD148E4',
                                      'hw_ver': '1.0',
                                      'ip': '10.0.1.2',
                                      'lang': 'en_US',
                                      'latitude': 0,
                                      'longitude': 0,
                                      'mac': 'F0-09-0D-00-00-00',
                                      'model': 'P110M',
                                      'nickname': 'I01BU0tFRF9OQU1FIw==',
                                      'oem_id': 'REDACTED_3446AA6011BFA704442ECBE',
                                      'on_time': 723,
                                      'overcurrent_status': 'normal',
                                      'overheat_status': 'normal',
                                      'power_protection_status': 'normal',
                                      'region': 'Australia/Sydney',
                                      'rssi': -50,
                                      'signal_level': 2,
                                      'specs': '',
                                      'ssid': 'I01BU0tFRF9TU0lEIw=',
                                      'time_diff': 600,
                                      'type': 'SMART.TAPOPLUG'}},
                          {'error_code': 0,
                           'method': 'get_connect_cloud_state',
                           'result': {'status': 1}}]}}
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required auto_off, adding AutoOff to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required cloud_connect, adding Cloud to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required device, adding DeviceModule to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required energy_monitoring, adding Energy to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required firmware, adding Firmware to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required led, adding Led to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required time, adding Time to modules.
DEBUG:kasa.smart.smartdevice:Querying 10.0.1.2 for modules: AutoOff, Energy, Firmware, Led, Time
DEBUG:kasa.smartprotocol:10.0.1.2 multi-request-batch-1-of-2 >> '{"method":"multipleRequest","request_time_milis":1731836979197,"terminal_uuid":"DR/K8KRIbCdJEYmleeeK3A==","params":{"requests":[{"method":"get_auto_off_config","params":{"start_index":0}},{"method":"get_energy_usage"},{"method":"get_current_power"},{"method":"get_auto_update_info"},{"method":"get_led_info"}]}}'
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/request
DEBUG:kasa.klaptransport:Device 10.0.1.2 query posted Host is 10.0.1.2, Sequence is -1490096694, Response status is 200, Request was {"method":"multipleRequest","request_time_milis":1731836979197,"terminal_uuid":"DR/K8KRIbCdJEYmleeeK3A==","params":{"requests":[{"method":"get_auto_off_config","params":{"start_index":0}},{"method":"get_energy_usage"},{"method":"get_current_power"},{"method":"get_auto_update_info"},{"method":"get_led_info"}]}}
DEBUG:kasa.klaptransport:Device 10.0.1.2 query response received
DEBUG:kasa.smartprotocol:10.0.1.2 multi-request-batch-1-of-2 << {'error_code': 0,
 'result': {'responses': [{'error_code': 0,
                           'method': 'get_auto_off_config',
                           'result': {'delay_min': 120, 'enable': False}},
                          {'error_code': -1003, 'method': 'get_energy_usage'},
                          {'error_code': 0,
                           'method': 'get_current_power',
                           'result': {'current_power': 0}},
                          {'error_code': 0,
                           'method': 'get_auto_update_info',
                           'result': {'enable': False,
                                      'random_range': 120,
                                      'time': 180}},
                          {'error_code': 0,
                           'method': 'get_led_info',
                           'result': {'bri_config': {'bri_type': 'overall',
                                                     'overall_bri': 50},
                                      'led_rule': 'always',
                                      'led_status': True,
                                      'night_mode': {'end_time': 420,
                                                     'night_mode_type': 'sunrise_sunset',
                                                     'start_time': 1140,
                                                     'sunrise_offset': 0,
                                                     'sunset_offset': 0}}}]}}
DEBUG:kasa.smartprotocol:10.0.1.2 multi-request-batch-2-of-2 >> '{"method":"multipleRequest","request_time_milis":1731836979217,"terminal_uuid":"DR/K8KRIbCdJEYmleeeK3A==","params":{"requests":[{"method":"get_device_time"}]}}'
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/request
DEBUG:kasa.klaptransport:Device 10.0.1.2 query posted Host is 10.0.1.2, Sequence is -1490096693, Response status is 200, Request was {"method":"multipleRequest","request_time_milis":1731836979217,"terminal_uuid":"DR/K8KRIbCdJEYmleeeK3A==","params":{"requests":[{"method":"get_device_time"}]}}
DEBUG:kasa.klaptransport:Device 10.0.1.2 query response received
DEBUG:kasa.smartprotocol:10.0.1.2 multi-request-batch-2-of-2 << {'error_code': 0,
 'result': {'responses': [{'error_code': 0,
                           'method': 'get_device_time',
                           'result': {'region': 'Australia/Sydney',
                                      'time_diff': 600,
                                      'timestamp': 946771937}}]}}
WARNING:kasa.smart.smartdevice:Error processing Energy for device 10.0.1.2, module will be unavailable: get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)
DEBUG:kasa.smart.smartdevice:Update completed 10.0.1.2: ['component_nego', 'get_device_info', 'get_connect_cloud_state', 'get_auto_off_config', 'get_energy_usage', 'get_current_power', 'get_auto_update_info', 'get_led_info', 'get_device_time']
== Primary features ==
State (state): True
Unable to read value (current_consumption): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))

== Information ==
Signal Level (signal_level): 2
Auto off at (auto_off_at): None
Cloud connection (cloud_connection): False
Unable to read value (consumption_today): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Unable to read value (consumption_this_month): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Update available (update_available): None
Check latest firmware (check_latest_firmware): <Action>

== Configuration ==
Auto off enabled (auto_off_enabled): False
Auto off in (auto_off_minutes): 120 min (range: 0-65536)
Auto update enabled (auto_update_enabled): False
LED (led): True

== Debug ==
Device ID (device_id): redacted
RSSI (rssi): -50 dBm
SSID (ssid): redacted
On since (on_since): 2000-01-02 11:00:14+11:00
Reboot (reboot): <Action>
Current firmware version (current_firmware_version): 1.2.3 Build 240617 Rel.153525
Available firmware version (available_firmware_version): None
Device time (device_time): 2000-01-02 11:12:17+11:00

--debug command get_energy_usage:
uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa --username redacted --password redacted --host 10.0.1.2 --debug command get_energy_usage Updated https://github.com/python-kasa/python-kasa.git (af8e648) Discovering device 10.0.1.2 for 10 seconds DEBUG:kasa.discover:[DISCOVERY] 10.0.1.2 >> {'system': {'get_sysinfo': {}}} DEBUG:kasa.discover:Waiting a total of 10 seconds for responses... DEBUG:kasa.klaptransport:Created KLAP transport for 10.0.1.2 DEBUG:kasa.discover:[DISCOVERY] 10.0.1.2 << {'error_code': 0, 'result': {'device_id': 'REDACTED_b9ba9abfe056e36ab947ec2', 'device_model': 'P110M(AU)', 'device_type': 'SMART.TAPOPLUG', 'factory_default': False, 'ip': '10.0.1.2', 'is_support_iot_cloud': True, 'mac': 'F0-09-0D-00-00-00', 'mgt_encrypt_schm': {'encrypt_type': 'KLAP', 'http_port': 80, 'is_support_https': False, 'lv': 2}, 'obd_src': 'tplink', 'owner': 'REDACTED_14252709E4C2C1AED6D6E5F', 'protocol_version': 1}} DEBUG:kasa.device:Initializing 10.0.1.2 of type <class 'kasa.smart.smartdevice.SmartDevice'> DEBUG:kasa.smartprotocol:10.0.1.2 >> '{"method":"get_energy_usage","request_time_milis":1731837155761,"terminal_uuid":"ZaaxKCqkszeXOW/uFzOpkQ=="}' DEBUG:kasa.klaptransport:Starting handshake with 10.0.1.2 DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/handshake1 DEBUG:kasa.klaptransport:Handshake1 posted at 2024-11-17 20:52:35.775833. Host is 10.0.1.2, Response status is 200, Request was 4baaf629da01544f235157b69ffe69b7 DEBUG:kasa.klaptransport:Handshake1 success at 2024-11-17 20:52:35.775925. Host is 10.0.1.2, Server remote_seed is: 2ade4c9a27134d986a15cf98ecb3cf99, server hash is: 7b6e3e3ef330de0b98225a3735e726aa3c2e501932e7486bb30ad85c5d709c2a DEBUG:kasa.klaptransport:handshake1 hashes match with expected credentials DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/handshake2 DEBUG:kasa.klaptransport:Handshake2 posted 2024-11-17 20:52:35.783052. Host is 10.0.1.2, Response status is 200, Request was 5c920e5a40acc57d7df1d530aa996d045b441009497b86fa2d3f43716b69fe8c DEBUG:kasa.klaptransport:Handshake with 10.0.1.2 complete DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/request DEBUG:kasa.klaptransport:Device 10.0.1.2 query posted Host is 10.0.1.2, Sequence is 1299707163, Response status is 200, Request was {"method":"get_energy_usage","request_time_milis":1731837155761,"terminal_uuid":"ZaaxKCqkszeXOW/uFzOpkQ=="} DEBUG:kasa.klaptransport:Device 10.0.1.2 query response received DEBUG:kasa.smartprotocol:10.0.1.2 << {'error_code': -1003} DEBUG:kasa.smartprotocol:Unable to query the device: 10.0.1.2, not retrying: Error querying device: 10.0.1.2: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR) Raised error: Error querying device: 10.0.1.2: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR) Traceback (most recent call last): File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/bin/kasa", line 10, in <module> sys.exit(cli()) ~~~^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/asyncclick/core.py", line 1205, in __call__ return anyio.run(self._main, main, args, kwargs, **opts) ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/anyio/_core/_eventloop.py", line 74, in run return async_backend.run(func, args, {}, backend_options) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2284, in run return runner.run(wrapper()) ~~~~~~~~~~^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2272, in wrapper return await func(*args) ^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/asyncclick/core.py", line 1208, in _main return await main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/asyncclick/core.py", line 1120, in main rv = await self.invoke(ctx) ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/cli/common.py", line 238, in invoke _handle_exception(self._debug, exc) ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/cli/common.py", line 236, in invoke return await super().invoke(ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/asyncclick/core.py", line 1739, in invoke return await _process_result(await sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/asyncclick/core.py", line 1485, in invoke return await ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/asyncclick/core.py", line 824, in invoke rv = await rv ^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/cli/common.py", line 129, in wrapper return await ctx.invoke(wrapped_function, dev, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/asyncclick/core.py", line 824, in invoke rv = await rv ^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/cli/main.py", line 446, in cmd_command res = await dev._query_helper(command, parameters) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/smart/smartdevice.py", line 596, in _query_helper res = await self.protocol.query({method: params}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/smartprotocol.py", line 89, in query return await self._query(request, retry_count) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/smartprotocol.py", line 150, in _query raise ex File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/smartprotocol.py", line 94, in _query return await self._execute_query( ^^^^^^^^^^^^^^^^^^^^^^^^^^ request, retry_count=retry, iterate_list_pages=True ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/smartprotocol.py", line 281, in _execute_query self._handle_response_error_code(response_data, smart_method) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/redacted/.cache/uv/archive-v0/DivdlyDiamBZjlAKczSBx/lib/python3.13/site-packages/kasa/smartprotocol.py", line 356, in _handle_response_error_code raise DeviceError(msg, error_code=error_code) kasa.exceptions.DeviceError: Error querying device: 10.0.1.2: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR)

@a81j
Copy link
Author

a81j commented Nov 17, 2024

uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa --username redacted --password redacted --host 10.0.1.2 --debug command get_current_power
works just fine

If the current power reading could get working in Home Assistant, then that is all I need.

@MrEbbinghaus
Copy link

@sdb9696 Same issue

Log
uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa --host 192.168.178.34 time get
 Updated https://github.com/python-kasa/python-kasa.git (af8e648)
Discovering device 192.168.178.34 for 10 seconds
WARNING:kasa.smart.smartdevice:Error processing Energy for device 192.168.178.34, module will be unavailable: get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)
Current time: 2000-01-02 01:24:58+01:00 (CET)uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa --host 192.168.178.34 --debug command get_energy_usage
 Updated https://github.com/python-kasa/python-kasa.git (af8e648)
Discovering device 192.168.178.34 for 10 seconds
DEBUG:kasa.discover:[DISCOVERY] 192.168.178.34 >> {'system': {'get_sysinfo': {}}}
DEBUG:kasa.discover:Waiting a total of 10 seconds for responses...
DEBUG:kasa.klaptransport:Created KLAP transport for 192.168.178.34
DEBUG:kasa.discover:[DISCOVERY] 192.168.178.34 << {'error_code': 0,
 'result': {'device_id': 'REDACTED_788d5dccb2d89e6bd1dbd23',
            'device_model': 'P110M(EU)',
            'device_type': 'SMART.TAPOPLUG',
            'factory_default': False,
            'ip': '192.168.178.34',
            'is_support_iot_cloud': True,
            'mac': 'F0-A7-31-00-00-00',
            'mgt_encrypt_schm': {'encrypt_type': 'KLAP',
                                 'http_port': 80,
                                 'is_support_https': False,
                                 'lv': 2},
            'obd_src': 'matter',
            'owner': '',
            'protocol_version': 1}}
DEBUG:kasa.device:Initializing 192.168.178.34 of type <class 'kasa.smart.smartdevice.SmartDevice'>
DEBUG:kasa.smartprotocol:192.168.178.34 >> '{"method":"get_energy_usage","request_time_milis":1731852044731,"terminal_uuid":"lF0HvSAeYVnoq1oukpQPng=="}'
DEBUG:kasa.klaptransport:Starting handshake with 192.168.178.34
DEBUG:kasa.httpclient:Posting to http://192.168.178.34/app/handshake1
DEBUG:kasa.klaptransport:Handshake1 posted at 2024-11-17 15:00:44.747457. Host is 192.168.178.34, Response status is 200, Request was 99b2a6ab9086b45745e783a4b133cb57
DEBUG:kasa.klaptransport:Handshake1 success at 2024-11-17 15:00:44.747552. Host is 192.168.178.34, Server remote_seed is: 877ba9f571082bf602f328f779caa9f6, server hash is: 099f93fb882d566b3779bc8c4ce95f9f3b6c8f3669842d1eb41842395c6c80b0
DEBUG:kasa.klaptransport:Server response doesn't match our expected hash on ip 192.168.178.34, but an authentication with TAPO default credentials matched
DEBUG:kasa.httpclient:Posting to http://192.168.178.34/app/handshake2
DEBUG:kasa.klaptransport:Handshake2 posted 2024-11-17 15:00:44.754906. Host is 192.168.178.34, Response status is 200, Request was f09aaba71029611c0bfa7d4cca6b66f2b141c2d9cc3d33c86db5be3dd7cb0a0a
DEBUG:kasa.klaptransport:Handshake with 192.168.178.34 complete
DEBUG:kasa.httpclient:Posting to http://192.168.178.34/app/request
DEBUG:kasa.klaptransport:Device 192.168.178.34 query posted Host is 192.168.178.34, Sequence is -552720194, Response status is 200, Request was {"method":"get_energy_usage","request_time_milis":1731852044731,"terminal_uuid":"lF0HvSAeYVnoq1oukpQPng=="}
DEBUG:kasa.klaptransport:Device 192.168.178.34 query response received
DEBUG:kasa.smartprotocol:192.168.178.34 << {'error_code': -1003}
DEBUG:kasa.smartprotocol:Unable to query the device: 192.168.178.34, not retrying: Error querying device: 192.168.178.34: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR)
Raised error: Error querying device: 192.168.178.34: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR)
Traceback (most recent call last):
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/bin/kasa", line 10, in <module>
    sys.exit(cli())
             ~~~^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/asyncclick/core.py", line 1205, in __call__
    return anyio.run(self._main, main, args, kwargs, **opts)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/anyio/_core/_eventloop.py", line 74, in run
    return async_backend.run(func, args, {}, backend_options)
           ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2284, in run
    return runner.run(wrapper())
           ~~~~~~~~~~^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/local/Cellar/python@3.13/3.13.0_1/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2272, in wrapper
    return await func(*args)
           ^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/asyncclick/core.py", line 1208, in _main
    return await main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/asyncclick/core.py", line 1120, in main
    rv = await self.invoke(ctx)
         ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/cli/common.py", line 238, in invoke
    _handle_exception(self._debug, exc)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/cli/common.py", line 236, in invoke
    return await super().invoke(ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/asyncclick/core.py", line 1739, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/asyncclick/core.py", line 1485, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/cli/common.py", line 129, in wrapper
    return await ctx.invoke(wrapped_function, dev, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/asyncclick/core.py", line 824, in invoke
    rv = await rv
         ^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/cli/main.py", line 446, in cmd_command
    res = await dev._query_helper(command, parameters)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/smart/smartdevice.py", line 596, in _query_helper
    res = await self.protocol.query({method: params})
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/smartprotocol.py", line 89, in query
    return await self._query(request, retry_count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/smartprotocol.py", line 150, in _query
    raise ex
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/smartprotocol.py", line 94, in _query
    return await self._execute_query(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
        request, retry_count=retry, iterate_list_pages=True
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/smartprotocol.py", line 281, in _execute_query
    self._handle_response_error_code(response_data, smart_method)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bjebb/Library/Caches/uv/archive-v0/qydokR5kDJ0CRcKXh6L7e/lib/python3.13/site-packages/kasa/smartprotocol.py", line 356, in _handle_response_error_code
    raise DeviceError(msg, error_code=error_code)
kasa.exceptions.DeviceError: Error querying device: 192.168.178.34: JSON_DECODE_FAIL_ERROR(-1003) for method: get_energy_usage (error_code=JSON_DECODE_FAIL_ERROR)


@donleistman Usually the plug sets the time automatically via NTP, but I blocked the device's access to the internet. Seems like it queries pool.ntp.org and time.nist.gov on boot, and then once an hour.


@a81j @donleistman

You can wrap large console outputs in HTML <detail> tags to have them collapsed. Leave at least one line of space between the Markdown content and the HTML tags for the nested Markdown to be rendered.

Example:

<details>
<summary>This is the title for the collapsed section</summary>

```console
> foo
my example log
```

</details>

becomes

This is the title for the collapsed section
> foo
my example log

@MrEbbinghaus
Copy link

Can someone test if this is an issue with other models as well?
This issue doesn't feel P110M specific.

@rytilahti
Copy link
Member

We may need to adjust our failure logic to allow graceful failing on multi-query modules. That way we could fall back even if a single query fails, like it seems to be in this case.

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 22, 2024

Hi @a81j and @MrEbbinghaus, any chance of an update fixture from the master branch?

@sdb9696 sdb9696 mentioned this issue Nov 25, 2024
sdb9696 added a commit that referenced this issue Nov 26, 2024
## [0.8.0](https://github.com/python-kasa/python-kasa/tree/0.8.0) (2024-11-26)

[Full Changelog](0.7.7...0.8.0)

**Release highlights:**

- **Initial support for devices using the Tapo camera protocol, i.e. Tapo cameras and the Tapo H200 hub.**
- New camera functionality such as exposing RTSP streaming urls and camera pan/tilt.
- New way of testing module support for individual features with `has_feature` and `get_feature`.
- Adding voltage and current monitoring to `smart` devices.
- Migration from pydantic to mashumaro for serialization.

Special thanks to @ryenitcher and @Puxtril for their new contributions to the improvement of the project! Also thanks to everyone who has helped with testing, contributing fixtures, and reporting issues!

**Breaking change notes:**

- Removed support for python <3.11. If you haven't got a compatible version try [uv](https://docs.astral.sh/uv/).
- Renamed `device_config.to_dict()` to `device_config.to_dict_control_credentials()`. `to_dict()` is still available but takes no parameters.
- From the `iot.Cloud` module the `iot.CloudInfo` class attributes have been converted to snake case.


**Breaking changes:**

- Migrate iot cloud module to mashumaro [\#1282](#1282) (@sdb9696)
- Replace custom deviceconfig serialization with mashumaru [\#1274](#1274) (@sdb9696)
- Remove support for python \<3.11 [\#1273](#1273) (@sdb9696)

**Implemented enhancements:**

- Update cli modify presets to support smart devices [\#1295](#1295) (@sdb9696)
- Use credentials\_hash for smartcamera rtsp url [\#1293](#1293) (@sdb9696)
- Add voltage and current monitoring to smart Devices [\#1281](#1281) (@ryenitcher)
- Update cli feature command for actions not to require a value [\#1264](#1264) (@sdb9696)
- Add pan tilt camera module [\#1261](#1261) (@sdb9696)
- Add alarm module for smartcamera hubs [\#1258](#1258) (@sdb9696)
- Move TAPO smartcamera out of experimental package [\#1255](#1255) (@sdb9696)
- Add SmartCamera Led Module [\#1249](#1249) (@sdb9696)
- Use component queries to select smartcamera modules [\#1248](#1248) (@sdb9696)
- Print formatting for IotLightPreset [\#1216](#1216) (@Puxtril)
- Allow getting Annotated features from modules [\#1018](#1018) (@sdb9696)
- Add common Thermostat module [\#977](#977) (@sdb9696)

**Fixed bugs:**

- TP-Link Tapo S505D cannot disable gradual on/off  [\#1309](#1309)
- Inconsistent emeter information between features and emeter cli [\#1308](#1308)
- How to dump power usage after latest updates? [\#1306](#1306)
- kasa.discover: Got unsupported connection type: 'device\_family': 'SMART.IPCAMERA' [\#1267](#1267)
- device \_\_repr\_\_ fails if no sys\_info [\#1262](#1262)
- Tapo P110M: Error processing Energy for device, module will be unavailable: get\_energy\_usage for Energy  [\#1243](#1243)
- Listing light presets throws error [\#1201](#1201)
- Include duration when disabling smooth transition on/off [\#1313](#1313) (@rytilahti)
- Expose energy command to cli [\#1307](#1307) (@rytilahti)
- Make discovery on unsupported devices less noisy [\#1291](#1291) (@rytilahti)
- Fix repr for device created with no sysinfo or discovery info" [\#1266](#1266) (@sdb9696)
- Fix discovery by alias for smart devices [\#1260](#1260) (@sdb9696)
- Make \_\_repr\_\_ work on discovery info [\#1233](#1233) (@rytilahti)

**Added support for devices:**

- Add HS200 \(US\) Smart Fixture [\#1303](#1303) (@ZeliardM)
- Add smartcamera devices to supported docs [\#1257](#1257) (@sdb9696)
- Add P110M\(AU\) fixture [\#1244](#1244) (@rytilahti)
- Add L630 fixture [\#1240](#1240) (@rytilahti)
- Add EP40M Fixture [\#1238](#1238) (@ryenitcher)
- Add KS220 Fixture [\#1237](#1237) (@ryenitcher)

**Documentation updates:**

- Use markdown footnotes in supported.md [\#1310](#1310) (@sdb9696)
- Update docs for the new module attributes has/get feature [\#1301](#1301) (@sdb9696)
- Fixup contributing.md for running test against a real device [\#1236](#1236) (@sdb9696)

**Project maintenance:**

- Rename tests/smartcamera to tests/smartcam [\#1315](#1315) (@sdb9696)
- Do not error on smartcam hub attached smartcam child devices [\#1314](#1314) (@sdb9696)
- Add P110M\(EU\) fixture [\#1305](#1305) (@sdb9696)
- Run tests with caplog in a single worker [\#1304](#1304) (@sdb9696)
- Rename smartcamera to smartcam [\#1300](#1300) (@sdb9696)
- Move iot fixtures into iot subfolder [\#1299](#1299) (@sdb9696)
- Annotate fan\_speed\_level of Fan interface [\#1298](#1298) (@sdb9696)
- Add PIR ADC Values to Test Fixtures [\#1296](#1296) (@ryenitcher)
- Exclude \_\_getattr\_\_ for deprecated attributes from type checkers [\#1294](#1294) (@sdb9696)
- Simplify omit http\_client in DeviceConfig serialization [\#1292](#1292) (@sdb9696)
- Add SMART Voltage Monitoring to Fixtures [\#1290](#1290) (@ryenitcher)
- Remove pydantic dependency [\#1289](#1289) (@sdb9696)
- Do not print out all the fixture names at the start of test runs [\#1287](#1287) (@sdb9696)
- dump\_devinfo: iot light strip commands [\#1286](#1286) (@sdb9696)
- Migrate TurnOnBehaviours to mashumaro [\#1285](#1285) (@sdb9696)
- dump\_devinfo: query smartlife.iot.common.cloud for fw updates [\#1284](#1284) (@rytilahti)
- Migrate RuleModule to mashumaro [\#1283](#1283) (@sdb9696)
- Update sphinx dependency to 6.2 to fix docs build [\#1280](#1280) (@sdb9696)
- Update DiscoveryResult to use mashu Annotated Alias [\#1279](#1279) (@sdb9696)
- Extend dump\_devinfo iot queries [\#1278](#1278) (@sdb9696)
- Migrate triggerlogs to mashumaru [\#1277](#1277) (@sdb9696)
- Migrate smart firmware module to mashumaro [\#1276](#1276) (@sdb9696)
- Migrate IotLightPreset to mashumaru [\#1275](#1275) (@sdb9696)
- Allow callable coroutines for feature setters [\#1272](#1272) (@sdb9696)
- Fix deprecated SSLContext\(\) usage [\#1271](#1271) (@sdb9696)
- Use \_get\_device\_info methods for smart and iot devs in devtools [\#1265](#1265) (@sdb9696)
- Remove experimental support [\#1256](#1256) (@sdb9696)
- Move protocol modules into protocols package [\#1254](#1254) (@sdb9696)
- Add linkcheck to readthedocs CI [\#1253](#1253) (@rytilahti)
- Update cli energy command to use energy module [\#1252](#1252) (@sdb9696)
- Consolidate warnings for fixtures missing child devices [\#1251](#1251) (@sdb9696)
- Update smartcamera fixtures with components [\#1250](#1250) (@sdb9696)
- Move transports into their own package [\#1247](#1247) (@rytilahti)
- Fix warnings in our test suite [\#1246](#1246) (@rytilahti)
- Move tests folder to top level of project [\#1242](#1242) (@sdb9696)
- Fix test framework running against real devices [\#1235](#1235) (@sdb9696)
- Add Additional Firmware Test Fixures [\#1234](#1234) (@ryenitcher)
- Update DiscoveryResult to use Mashumaro instead of pydantic [\#1231](#1231) (@sdb9696)
- Update fixture for ES20M 1.0.11 [\#1215](#1215) (@rytilahti)
- Enable ruff check for ANN [\#1139](#1139) (@rytilahti)

**Closed issues:**

- Expose Fan speed range from the library [\#1008](#1008)
- \[META\] 0.7 series - module support for SMART devices, support for introspectable device features and refactoring the library [\#783](#783)
@a81j
Copy link
Author

a81j commented Nov 28, 2024

Still doesn't show power reading in Home assistant dev. The power reading is "Unavailable"

uvx --from "python-kasa[speedups] @ git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter" kasa --username redacted --password redacted --host 10.0.1.2 --debug feature

now shows the correct power reading in there, but gives the same error as before as well:

Updated https://github.com/python-kasa/python-kasa.git (750cebb)
Discovering device 10.0.1.2 for 10 seconds
DEBUG:kasa.discover:[DISCOVERY] 10.0.1.2 >> {'system': {'get_sysinfo': {}}}
DEBUG:kasa.discover:Waiting a total of 10 seconds for responses...
DEBUG:kasa.transports.klaptransport:Created KLAP transport for 10.0.1.2
DEBUG:kasa.discover:[DISCOVERY] 10.0.1.2 << {'error_code': 0,
'result': {'device_id': 'REDACTED_b9ba9abfe056e36ab947ec2',
           'device_model': 'P110M(AU)',
           'device_type': 'SMART.TAPOPLUG',
           'factory_default': False,
           'ip': '10.0.1.2',
           'is_support_iot_cloud': True,
           'mac': 'F0-09-0D-00-00-00',
           'mgt_encrypt_schm': {'encrypt_type': 'KLAP',
                                'http_port': 80,
                                'is_support_https': False,
                                'lv': 2},
           'obd_src': 'tplink',
           'owner': 'REDACTED_14252709E4C2C1AED6D6E5F',
           'protocol_version': 1}}
DEBUG:kasa.device:Initializing 10.0.1.2 of type <class 'kasa.smart.smartdevice.SmartDevice'>
DEBUG:kasa.protocols.smartprotocol:10.0.1.2 multi-request-batch-1-of-1 >> '{"method":"multipleRequest","request_time_milis":1732811762011,"terminal_uuid":"+ZiA8zqQG/GwwSKioNZQHg==","params":{"requests":[{"method":"component_nego"},{"method":"get_device_info"},{"method":"get_connect_cloud_state"}]}}'
DEBUG:kasa.transports.klaptransport:Starting handshake with 10.0.1.2
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/handshake1
DEBUG:kasa.transports.klaptransport:Handshake1 posted at 2024-11-29 03:36:02.024311. Host is 10.0.1.2, Response status is 200, Request was a4a3a64d4e12afa6d61b0cbbc92bd838
DEBUG:kasa.transports.klaptransport:Handshake1 success at 2024-11-29 03:36:02.024380. Host is 10.0.1.2, Server remote_seed is: 4bbf63999c376399945c6399ff586399, server hash is: 95ae5e7237af847e464a3c12c6891d0f0e5a5470cc7506dc8c46ab1c8f03e493
DEBUG:kasa.transports.klaptransport:handshake1 hashes match with expected credentials
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/handshake2
DEBUG:kasa.transports.klaptransport:Handshake2 posted 2024-11-29 03:36:02.031216. Host is 10.0.1.2, Response status is 200, Request was cc8336fecf2dc9a9ed732d7bd05e7fbe12fb2e5ad42c81879451a447bef031a2
DEBUG:kasa.transports.klaptransport:Handshake with 10.0.1.2 complete
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/request
DEBUG:kasa.transports.klaptransport:Device 10.0.1.2 query posted Host is 10.0.1.2, Sequence is 1770431398, Response status is 200, Request was {"method":"multipleRequest","request_time_milis":1732811762011,"terminal_uuid":"+ZiA8zqQG/GwwSKioNZQHg==","params":{"requests":[{"method":"component_nego"},{"method":"get_device_info"},{"method":"get_connect_cloud_state"}]}}
DEBUG:kasa.transports.klaptransport:Device 10.0.1.2 query response received
DEBUG:kasa.protocols.smartprotocol:10.0.1.2 multi-request-batch-1-of-1 << {'error_code': 0,
'result': {'responses': [{'error_code': 0,
                          'method': 'component_nego',
                          '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': 'localSmart',
                                                         'ver_code': 1},
                                                        {'id': 'energy_monitoring',
                                                         'ver_code': 2},
                                                        {'id': 'power_protection',
                                                         'ver_code': 1},
                                                        {'id': 'charging_protection',
                                                         'ver_code': 2},
                                                        {'id': 'matter',
                                                         'ver_code': 2},
                                                        {'id': 'current_protection',
                                                         'ver_code': 1}]}},
                         {'error_code': 0,
                          'method': 'get_device_info',
                          'result': {'auto_off_remain_time': 0,
                                     'auto_off_status': 'off',
                                     'avatar': 'plug',
                                     'charging_status': 'normal',
                                     'default_states': {'state': {},
                                                        'type': 'last_states'},
                                     'device_id': 'REDACTED_4233F584FA8A442C95CFF922300F272',
                                     'device_on': True,
                                     'fw_id': '00000000000000000000000000000000',
                                     'fw_ver': '1.2.3 Build 240617 Rel.153525',
                                     'has_set_location_info': False,
                                     'hw_id': 'redacted',
                                     'hw_ver': '1.0',
                                     'ip': '10.0.1.2',
                                     'lang': 'en_US',
                                     'latitude': 0,
                                     'longitude': 0,
                                     'mac': 'F0-09-0D-00-00-00',
                                     'model': 'P110M',
                                     'nickname': 'I01BU0tFRF9OQU1FIw==',
                                     'oem_id': 'REDACTED_3446AA6011BFA704442ECBE',
                                     'on_time': 975507,
                                     'overcurrent_status': 'normal',
                                     'overheat_status': 'normal',
                                     'power_protection_status': 'normal',
                                     'region': 'Australia/Sydney',
                                     'rssi': -49,
                                     'signal_level': 3,
                                     'specs': '',
                                     'ssid': 'I01BU0tFRF9TU0lEIw=',
                                     'time_diff': 600,
                                     'type': 'SMART.TAPOPLUG'}},
                         {'error_code': 0,
                          'method': 'get_connect_cloud_state',
                          'result': {'status': 1}}]}}
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required auto_off, adding AutoOff to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required cloud_connect, adding Cloud to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required device, adding DeviceModule to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required energy_monitoring, adding Energy to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required firmware, adding Firmware to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required led, adding Led to modules.
DEBUG:kasa.smart.smartdevice:Device 10.0.1.2, found required time, adding Time to modules.
DEBUG:kasa.smart.smartdevice:Querying 10.0.1.2 for modules: AutoOff, Energy, Firmware, Led, Time
DEBUG:kasa.protocols.smartprotocol:10.0.1.2 multi-request-batch-1-of-2 >> '{"method":"multipleRequest","request_time_milis":1732811762061,"terminal_uuid":"+ZiA8zqQG/GwwSKioNZQHg==","params":{"requests":[{"method":"get_auto_off_config","params":{"start_index":0}},{"method":"get_energy_usage"},{"method":"get_current_power"},{"method":"get_emeter_data"},{"method":"get_emeter_vgain_igain"}]}}'
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/request
DEBUG:kasa.transports.klaptransport:Device 10.0.1.2 query posted Host is 10.0.1.2, Sequence is 1770431399, Response status is 200, Request was {"method":"multipleRequest","request_time_milis":1732811762061,"terminal_uuid":"+ZiA8zqQG/GwwSKioNZQHg==","params":{"requests":[{"method":"get_auto_off_config","params":{"start_index":0}},{"method":"get_energy_usage"},{"method":"get_current_power"},{"method":"get_emeter_data"},{"method":"get_emeter_vgain_igain"}]}}
DEBUG:kasa.transports.klaptransport:Device 10.0.1.2 query response received
DEBUG:kasa.protocols.smartprotocol:10.0.1.2 multi-request-batch-1-of-2 << {'error_code': 0,
'result': {'responses': [{'error_code': 0,
                          'method': 'get_auto_off_config',
                          'result': {'delay_min': 120, 'enable': False}},
                         {'error_code': -1003, 'method': 'get_energy_usage'},
                         {'error_code': 0,
                          'method': 'get_current_power',
                          'result': {'current_power': 1}},
                         {'error_code': 0,
                          'method': 'get_emeter_data',
                          'result': {'current_ma': 27,
                                     'energy_wh': 507,
                                     'power_mw': 1835,
                                     'voltage_mv': 236798}},
                         {'error_code': 0,
                          'method': 'get_emeter_vgain_igain',
                          'result': {'igain': 11409, 'vgain': 124834}}]}}
DEBUG:kasa.protocols.smartprotocol:10.0.1.2 multi-request-batch-2-of-2 >> '{"method":"multipleRequest","request_time_milis":1732811762076,"terminal_uuid":"+ZiA8zqQG/GwwSKioNZQHg==","params":{"requests":[{"method":"get_auto_update_info"},{"method":"get_led_info"},{"method":"get_device_time"}]}}'
DEBUG:kasa.httpclient:Posting to http://10.0.1.2/app/request
DEBUG:kasa.transports.klaptransport:Device 10.0.1.2 query posted Host is 10.0.1.2, Sequence is 1770431400, Response status is 200, Request was {"method":"multipleRequest","request_time_milis":1732811762076,"terminal_uuid":"+ZiA8zqQG/GwwSKioNZQHg==","params":{"requests":[{"method":"get_auto_update_info"},{"method":"get_led_info"},{"method":"get_device_time"}]}}
DEBUG:kasa.transports.klaptransport:Device 10.0.1.2 query response received
DEBUG:kasa.protocols.smartprotocol:10.0.1.2 multi-request-batch-2-of-2 << {'error_code': 0,
'result': {'responses': [{'error_code': 0,
                          'method': 'get_auto_update_info',
                          'result': {'enable': False,
                                     'random_range': 120,
                                     'time': 180}},
                         {'error_code': 0,
                          'method': 'get_led_info',
                          'result': {'bri_config': {'bri_type': 'overall',
                                                    'overall_bri': 50},
                                     'led_rule': 'always',
                                     'led_status': True,
                                     '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': 'Australia/Sydney',
                                     'time_diff': 600,
                                     'timestamp': 947746721}}]}}
WARNING:kasa.smart.smartdevice:Error processing Energy for device 10.0.1.2, module will be unavailable: get_energy_usage for Energy (error_code=JSON_DECODE_FAIL_ERROR)
DEBUG:kasa.smart.smartdevice:Update completed 10.0.1.2: ['component_nego', 'get_device_info', 'get_connect_cloud_state', 'get_auto_off_config', 'get_energy_usage', 'get_current_power', 'get_emeter_data', 'get_emeter_vgain_igain', 'get_auto_update_info', 'get_led_info', 'get_device_time']
== Primary features ==
State (state): True
Unable to read value (current_consumption): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))

== Information ==
Signal Level (signal_level): 3
Auto off at (auto_off_at): None
Cloud connection (cloud_connection): False
Unable to read value (consumption_today): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Unable to read value (consumption_this_month): ('Module update error', DeviceError(<SmartErrorCode.JSON_DECODE_FAIL_ERROR: -1003>))
Update available (update_available): None
Check latest firmware (check_latest_firmware): <Action>

== Configuration ==
Auto off enabled (auto_off_enabled): False
Auto off in (auto_off_minutes): 120 min (range: 0-65536)
Auto update enabled (auto_update_enabled): False
LED (led): True

== Debug ==
Device ID (device_id): redacted
RSSI (rssi): -49 dBm
SSID (ssid): redacted
On since (on_since): 2000-01-02 11:00:14+11:00
Reboot (reboot): <Action>
Current firmware version (current_firmware_version): 1.2.3 Build 240617 Rel.153525
Available firmware version (available_firmware_version): None
Device time (device_time): 2000-01-13 17:58:41+11:00

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 28, 2024

The device time is set to 2000-01-13 17:58:41+11:00 which causes this issue. Try:

uvx --from python-kasa[speedups] kasa --username redacted --password redacted --host 10.0.1.2 time sync

@a81j
Copy link
Author

a81j commented Nov 28, 2024

The current_consumption shouldn't require the time to be set correctly.

Maybe it might be needed for todays_consumption or this_month_s_consumption

Unfortunately, I can't have the time set correctly always on this, but I need to be able to see the current_consumption to detect if a device is currently in use.

@a81j
Copy link
Author

a81j commented Nov 28, 2024

kasa command get_current_power works perfectly with the time wrong, so it should be possible to get it into home assistant.

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 28, 2024

Can you try again with the latest commit to #1245 please.

@a81j
Copy link
Author

a81j commented Nov 28, 2024

kasa feature now gives no error and works perfectly

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 28, 2024

Presumably these numbers are all reporting 0 though?

Today's consumption (consumption_today): 0.0 kWh
This month's consumption (consumption_this_month): 0.0 kWh

@a81j
Copy link
Author

a81j commented Nov 28, 2024

They are reporting 0.0 yes. There is only a 2W load on it so I can't see if it should be something else.

Reporting today's and monthly consumption doesn't make a difference for my use case. Even if I did need it, Home Assistant can generate and record those values from the current consumption easily.

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 28, 2024

They're only available in the module that is erroring and they get set to 0 in that case. @rytilahti maybe we should return None on these if not available so that it doesn't mess up HA's TOTAL_INCREASING function?

@rytilahti
Copy link
Member

rytilahti commented Nov 28, 2024

So this behavior of returning "0" for unavailable values might have been copied over from the homeassistant integration, so I went down the git blame history and found out that https://github.com/home-assistant/core/pull/53596/files#diff-d1aee68b279979c0c59cf7c893fec0964f0e03f84a2a761937940c541e0d176aL165-L168 was the PR that changed the behavior.

If my memory serves me correctly, the reason for this hack was that the entities were initialized only during the startup, so if your device reported no information (e.g., if there was no consumption for the day after a midnight restart or so), there would be no entity created until the next HA restart.

I think we should return None for unavailable information (and maybe suppress creation of such entities?), but we want to avoid reintroducing the issue this hack aimed to solve.

@sdb9696
Copy link
Collaborator

sdb9696 commented Nov 29, 2024

If my memory serves me correctly, the reason for this hack was that the entities were initialized only during the startup, so if your device reported no information (e.g., if there was no consumption for the day after a midnight restart or so), there would be no entity created until the next HA restart.

This is no longer the behaviour since the move to the feature entities. The logic now is that if the feature is there, the entity is created regardless of value.

I think we should return None for unavailable information (and maybe suppress creation of such entities?), but we want to avoid reintroducing the issue this hack aimed to solve.

I don't think we should suppress the creation as the error could be (and usually is) intermittent. The latest commit to 1245 will return None for the consumption values on error.

rytilahti pushed a commit that referenced this issue Nov 29, 2024
## [0.8.0](https://github.com/python-kasa/python-kasa/tree/0.8.0) (2024-11-26)

[Full Changelog](0.7.7...0.8.0)

**Release highlights:**

- **Initial support for devices using the Tapo camera protocol, i.e. Tapo cameras and the Tapo H200 hub.**
- New camera functionality such as exposing RTSP streaming urls and camera pan/tilt.
- New way of testing module support for individual features with `has_feature` and `get_feature`.
- Adding voltage and current monitoring to `smart` devices.
- Migration from pydantic to mashumaro for serialization.

Special thanks to @ryenitcher and @Puxtril for their new contributions to the improvement of the project! Also thanks to everyone who has helped with testing, contributing fixtures, and reporting issues!

**Breaking change notes:**

- Removed support for python <3.11. If you haven't got a compatible version try [uv](https://docs.astral.sh/uv/).
- Renamed `device_config.to_dict()` to `device_config.to_dict_control_credentials()`. `to_dict()` is still available but takes no parameters.
- From the `iot.Cloud` module the `iot.CloudInfo` class attributes have been converted to snake case.


**Breaking changes:**

- Migrate iot cloud module to mashumaro [\#1282](#1282) (@sdb9696)
- Replace custom deviceconfig serialization with mashumaru [\#1274](#1274) (@sdb9696)
- Remove support for python \<3.11 [\#1273](#1273) (@sdb9696)

**Implemented enhancements:**

- Update cli modify presets to support smart devices [\#1295](#1295) (@sdb9696)
- Use credentials\_hash for smartcamera rtsp url [\#1293](#1293) (@sdb9696)
- Add voltage and current monitoring to smart Devices [\#1281](#1281) (@ryenitcher)
- Update cli feature command for actions not to require a value [\#1264](#1264) (@sdb9696)
- Add pan tilt camera module [\#1261](#1261) (@sdb9696)
- Add alarm module for smartcamera hubs [\#1258](#1258) (@sdb9696)
- Move TAPO smartcamera out of experimental package [\#1255](#1255) (@sdb9696)
- Add SmartCamera Led Module [\#1249](#1249) (@sdb9696)
- Use component queries to select smartcamera modules [\#1248](#1248) (@sdb9696)
- Print formatting for IotLightPreset [\#1216](#1216) (@Puxtril)
- Allow getting Annotated features from modules [\#1018](#1018) (@sdb9696)
- Add common Thermostat module [\#977](#977) (@sdb9696)

**Fixed bugs:**

- TP-Link Tapo S505D cannot disable gradual on/off  [\#1309](#1309)
- Inconsistent emeter information between features and emeter cli [\#1308](#1308)
- How to dump power usage after latest updates? [\#1306](#1306)
- kasa.discover: Got unsupported connection type: 'device\_family': 'SMART.IPCAMERA' [\#1267](#1267)
- device \_\_repr\_\_ fails if no sys\_info [\#1262](#1262)
- Tapo P110M: Error processing Energy for device, module will be unavailable: get\_energy\_usage for Energy  [\#1243](#1243)
- Listing light presets throws error [\#1201](#1201)
- Include duration when disabling smooth transition on/off [\#1313](#1313) (@rytilahti)
- Expose energy command to cli [\#1307](#1307) (@rytilahti)
- Make discovery on unsupported devices less noisy [\#1291](#1291) (@rytilahti)
- Fix repr for device created with no sysinfo or discovery info" [\#1266](#1266) (@sdb9696)
- Fix discovery by alias for smart devices [\#1260](#1260) (@sdb9696)
- Make \_\_repr\_\_ work on discovery info [\#1233](#1233) (@rytilahti)

**Added support for devices:**

- Add HS200 \(US\) Smart Fixture [\#1303](#1303) (@ZeliardM)
- Add smartcamera devices to supported docs [\#1257](#1257) (@sdb9696)
- Add P110M\(AU\) fixture [\#1244](#1244) (@rytilahti)
- Add L630 fixture [\#1240](#1240) (@rytilahti)
- Add EP40M Fixture [\#1238](#1238) (@ryenitcher)
- Add KS220 Fixture [\#1237](#1237) (@ryenitcher)

**Documentation updates:**

- Use markdown footnotes in supported.md [\#1310](#1310) (@sdb9696)
- Update docs for the new module attributes has/get feature [\#1301](#1301) (@sdb9696)
- Fixup contributing.md for running test against a real device [\#1236](#1236) (@sdb9696)

**Project maintenance:**

- Rename tests/smartcamera to tests/smartcam [\#1315](#1315) (@sdb9696)
- Do not error on smartcam hub attached smartcam child devices [\#1314](#1314) (@sdb9696)
- Add P110M\(EU\) fixture [\#1305](#1305) (@sdb9696)
- Run tests with caplog in a single worker [\#1304](#1304) (@sdb9696)
- Rename smartcamera to smartcam [\#1300](#1300) (@sdb9696)
- Move iot fixtures into iot subfolder [\#1299](#1299) (@sdb9696)
- Annotate fan\_speed\_level of Fan interface [\#1298](#1298) (@sdb9696)
- Add PIR ADC Values to Test Fixtures [\#1296](#1296) (@ryenitcher)
- Exclude \_\_getattr\_\_ for deprecated attributes from type checkers [\#1294](#1294) (@sdb9696)
- Simplify omit http\_client in DeviceConfig serialization [\#1292](#1292) (@sdb9696)
- Add SMART Voltage Monitoring to Fixtures [\#1290](#1290) (@ryenitcher)
- Remove pydantic dependency [\#1289](#1289) (@sdb9696)
- Do not print out all the fixture names at the start of test runs [\#1287](#1287) (@sdb9696)
- dump\_devinfo: iot light strip commands [\#1286](#1286) (@sdb9696)
- Migrate TurnOnBehaviours to mashumaro [\#1285](#1285) (@sdb9696)
- dump\_devinfo: query smartlife.iot.common.cloud for fw updates [\#1284](#1284) (@rytilahti)
- Migrate RuleModule to mashumaro [\#1283](#1283) (@sdb9696)
- Update sphinx dependency to 6.2 to fix docs build [\#1280](#1280) (@sdb9696)
- Update DiscoveryResult to use mashu Annotated Alias [\#1279](#1279) (@sdb9696)
- Extend dump\_devinfo iot queries [\#1278](#1278) (@sdb9696)
- Migrate triggerlogs to mashumaru [\#1277](#1277) (@sdb9696)
- Migrate smart firmware module to mashumaro [\#1276](#1276) (@sdb9696)
- Migrate IotLightPreset to mashumaru [\#1275](#1275) (@sdb9696)
- Allow callable coroutines for feature setters [\#1272](#1272) (@sdb9696)
- Fix deprecated SSLContext\(\) usage [\#1271](#1271) (@sdb9696)
- Use \_get\_device\_info methods for smart and iot devs in devtools [\#1265](#1265) (@sdb9696)
- Remove experimental support [\#1256](#1256) (@sdb9696)
- Move protocol modules into protocols package [\#1254](#1254) (@sdb9696)
- Add linkcheck to readthedocs CI [\#1253](#1253) (@rytilahti)
- Update cli energy command to use energy module [\#1252](#1252) (@sdb9696)
- Consolidate warnings for fixtures missing child devices [\#1251](#1251) (@sdb9696)
- Update smartcamera fixtures with components [\#1250](#1250) (@sdb9696)
- Move transports into their own package [\#1247](#1247) (@rytilahti)
- Fix warnings in our test suite [\#1246](#1246) (@rytilahti)
- Move tests folder to top level of project [\#1242](#1242) (@sdb9696)
- Fix test framework running against real devices [\#1235](#1235) (@sdb9696)
- Add Additional Firmware Test Fixures [\#1234](#1234) (@ryenitcher)
- Update DiscoveryResult to use Mashumaro instead of pydantic [\#1231](#1231) (@sdb9696)
- Update fixture for ES20M 1.0.11 [\#1215](#1215) (@rytilahti)
- Enable ruff check for ANN [\#1139](#1139) (@rytilahti)

**Closed issues:**

- Expose Fan speed range from the library [\#1008](#1008)
- \[META\] 0.7 series - module support for SMART devices, support for introspectable device features and refactoring the library [\#783](#783)
@a81j
Copy link
Author

a81j commented Nov 30, 2024

Working perfectly in Home Assistant when testing using the following:

"requirements": ["git+https://github.com/python-kasa/python-kasa.git@fix/p110m_emeter"]

Thank you

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
5 participants