Skip to content

Conversation

@balloob
Copy link
Member

@balloob balloob commented Apr 3, 2020

Breaking change

Proposed change

Speed up changing the state of TP-Link lights by making a single request instead of doing one request per parameter that we want to change.

This PR is untested, looking for testers with TP-Link. @rytilahti maybe?

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@probot-home-assistant
Copy link

Hey there @rytilahti, mind taking a look at this pull request as its been labeled with a integration (tplink) you are listed as a codeowner for? Thanks!

@rytilahti
Copy link
Member

rytilahti commented Apr 3, 2020

I don't have access to any test devices, but my understanding is that this should work. If that's the case, there is no need to create a diff on settings to change. Simply checking if the current settings differ from the wanted ones should suffice (i.e., if old_state_param != new_state param).

@bdraco
Copy link
Member

bdraco commented Apr 5, 2020

I'll dig one up out of the garage later this week if nobody has one available to test.

@balloob
Copy link
Member Author

balloob commented Apr 5, 2020

@bramkragten is going to test it.

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

Had a chance to test this on 0.108 and found there is a problem before the change

2020-04-06 19:27:22 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 231, in do_update_retry
    self._light_state = self.get_light_state_retry(self._light_features)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 294, in get_light_state_retry
    return self.get_light_state(light_features)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 310, in get_light_state
    brightness = brightness_from_percentage(self.smartbulb.brightness)
  File "/usr/local/lib/python3.7/site-packages/pyHS100/smartbulb.py", line 222, in brightness
    return int(light_state['brightness'])
KeyError: 'brightness'
2020-04-06 19:27:48 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 231, in do_update_retry
    self._light_state = self.get_light_state_retry(self._light_features)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 294, in get_light_state_retry
    return self.get_light_state(light_features)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 314, in get_light_state
    color_temp = kelvin_to_mired(self.smartbulb.color_temp)
  File "/usr/src/homeassistant/homeassistant/util/color.py", line 515, in color_temperature_kelvin_to_mired
    return math.floor(1000000 / kelvin_temperature)
ZeroDivisionError: division by zero

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

After the change

2020-04-06 19:31:18 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.139967528218000] unsupported operand type(s) for /: 'int' and 'NoneType'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1250, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1285, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    self._platforms.values(), func, call, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 412, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 600, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 443, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 243, in async_handle_light_on_service
    await light.async_turn_on(**params)
  File "/config/custom_components/tplink/light.py", line 174, in async_turn_on
    emeter_params=self._light_state.emeter_params,
  File "/config/custom_components/tplink/light.py", line 366, in async_set_light_state_retry
    self.set_light_state, old_light_state, new_light_state
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tplink/light.py", line 390, in set_light_state
    old_state_param = old_light_state.to_param()
  File "/config/custom_components/tplink/light.py", line 92, in to_param
    "color_temp": mired_to_kelvin(self.color_temp),
  File "/usr/src/homeassistant/homeassistant/util/color.py", line 510, in color_temperature_mired_to_kelvin
    return math.floor(1000000 / mired_temperature)
TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

Summary:

@balloob

Before:
Error in the log but working

After:
Not working, different errors

@balloob
Copy link
Member Author

balloob commented Apr 6, 2020

Your current error on 108 is weird, there is a guard for it:

if self.smartbulb.color_temp is not None and self.smartbulb.color_temp != 0:
color_temp = kelvin_to_mired(self.smartbulb.color_temp)

Pushed a fix for the 2nd.

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

No more log errors, brightness works, color temp.

Setting hue/sat is broken. Tried multiple colors. Nothing happens

@rytilahti
Copy link
Member

Maybe color temp overrides the hue/sat? That would explain why it is not working when temp is also given. Anyway, you should probably enable debug logging for pyHS100 and check the logs to see what sort of input & output you are getting.

Here's how it looks like in raw responses from a device (ignore that this is a different repo, the payloads are the same): https://github.com/python-kasa/python-kasa/blob/master/kasa/tests/fixtures/KL120(US)_1.0_real.json#L17

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

Maybe color temp overrides the hue/sat? That would explain why it is not working when temp is also given. Anyway, you should probably enable debug logging for pyHS100

Did that. Yikes. This thing is a firehose

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

Every 5 seconds

2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (33) {"system": {"get_sysinfo": null}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] < (1005) {"system":{"get_sysinfo":{"sw_ver":"1.8.11 Build 191113 Rel.105336","hw_ver":"1.0","model":"KL130(US)","description":"Smart Wi-Fi LED Bulb with Color Changing","alias":"Nick office tplink","mic_type":"IOT.SMARTBULB","dev_state":"normal","mic_mac":"1C3BF373CA4E","deviceId":"8012AB6D46CD2944174CE8749A76C55C1C8D9B28","oemId":"ECEF0F3973FD44972286224ACCDA255A","hwId":"111E35908497A05512E259BB76801E10","is_factory":false,"disco_ver":"1.0","ctrl_protocols":{"name":"Linkie","version":"1.0"},"light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100},"is_dimmable":1,"is_color":1,"is_variable_color_temp":1,"preferred_state":[{"index":0,"hue":0,"saturation":0,"color_temp":2700,"brightness":50},{"index":1,"hue":0,"saturation":75,"color_temp":0,"brightness":100},{"index":2,"hue":120,"saturation":75,"color_temp":0,"brightness":100},{"index":3,"hue":240,"saturation":75,"color_temp":0,"brightness":100}],"rssi":-43,"active_mode":"none","heapsize":306744,"err_code":0}}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (33) {"system": {"get_sysinfo": null}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] < (1005) {"system":{"get_sysinfo":{"sw_ver":"1.8.11 Build 191113 Rel.105336","hw_ver":"1.0","model":"KL130(US)","description":"Smart Wi-Fi LED Bulb with Color Changing","alias":"Nick office tplink","mic_type":"IOT.SMARTBULB","dev_state":"normal","mic_mac":"1C3BF373CA4E","deviceId":"8012AB6D46CD2944174CE8749A76C55C1C8D9B28","oemId":"ECEF0F3973FD44972286224ACCDA255A","hwId":"111E35908497A05512E259BB76801E10","is_factory":false,"disco_ver":"1.0","ctrl_protocols":{"name":"Linkie","version":"1.0"},"light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100},"is_dimmable":1,"is_color":1,"is_variable_color_temp":1,"preferred_state":[{"index":0,"hue":0,"saturation":0,"color_temp":2700,"brightness":50},{"index":1,"hue":0,"saturation":75,"color_temp":0,"brightness":100},{"index":2,"hue":120,"saturation":75,"color_temp":0,"brightness":100},{"index":3,"hue":240,"saturation":75,"color_temp":0,"brightness":100}],"rssi":-43,"active_mode":"none","heapsize":306744,"err_code":0}}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:35 DEBUG (SyncWorker_1) [pyHS100.protocol] > (33) {"system": {"get_sysinfo": null}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] < (1005) {"system":{"get_sysinfo":{"sw_ver":"1.8.11 Build 191113 Rel.105336","hw_ver":"1.0","model":"KL130(US)","description":"Smart Wi-Fi LED Bulb with Color Changing","alias":"Nick office tplink","mic_type":"IOT.SMARTBULB","dev_state":"normal","mic_mac":"1C3BF373CA4E","deviceId":"8012AB6D46CD2944174CE8749A76C55C1C8D9B28","oemId":"ECEF0F3973FD44972286224ACCDA255A","hwId":"111E35908497A05512E259BB76801E10","is_factory":false,"disco_ver":"1.0","ctrl_protocols":{"name":"Linkie","version":"1.0"},"light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100},"is_dimmable":1,"is_color":1,"is_variable_color_temp":1,"preferred_state":[{"index":0,"hue":0,"saturation":0,"color_temp":2700,"brightness":50},{"index":1,"hue":0,"saturation":75,"color_temp":0,"brightness":100},{"index":2,"hue":120,"saturation":75,"color_temp":0,"brightness":100},{"index":3,"hue":240,"saturation":75,"color_temp":0,"brightness":100}],"rssi":-43,"active_mode":"none","heapsize":306744,"err_code":0}}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] > (33) {"system": {"get_sysinfo": null}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] < (1005) {"system":{"get_sysinfo":{"sw_ver":"1.8.11 Build 191113 Rel.105336","hw_ver":"1.0","model":"KL130(US)","description":"Smart Wi-Fi LED Bulb with Color Changing","alias":"Nick office tplink","mic_type":"IOT.SMARTBULB","dev_state":"normal","mic_mac":"1C3BF373CA4E","deviceId":"8012AB6D46CD2944174CE8749A76C55C1C8D9B28","oemId":"ECEF0F3973FD44972286224ACCDA255A","hwId":"111E35908497A05512E259BB76801E10","is_factory":false,"disco_ver":"1.0","ctrl_protocols":{"name":"Linkie","version":"1.0"},"light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100},"is_dimmable":1,"is_color":1,"is_variable_color_temp":1,"preferred_state":[{"index":0,"hue":0,"saturation":0,"color_temp":2700,"brightness":50},{"index":1,"hue":0,"saturation":75,"color_temp":0,"brightness":100},{"index":2,"hue":120,"saturation":75,"color_temp":0,"brightness":100},{"index":3,"hue":240,"saturation":75,"color_temp":0,"brightness":100}],"rssi":-43,"active_mode":"none","heapsize":306744,"err_code":0}}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] > (70) {"smartlife.iot.smartbulb.lightingservice": {"get_light_state": null}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] < (160) {"smartlife.iot.smartbulb.lightingservice":{"get_light_state":{"on_off":1,"mode":"normal","hue":0,"saturation":0,"color_temp":0,"brightness":100,"err_code":0}}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] > (55) {"smartlife.iot.common.emeter": {"get_realtime": null}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] < (80) {"smartlife.iot.common.emeter":{"get_realtime":{"power_mw":10800,"err_code":0}}}
2020-04-06 22:18:36 DEBUG (SyncWorker_1) [pyHS100.protocol] > (76) {"smartlife.iot.common.emeter": {"get_daystat": {"month": 4, "year": 2020}}}
2020-04-06 22:18:37 DEBUG (SyncWorker_1) [pyHS100.protocol] < (122) {"smartlife.iot.common.emeter":{"get_daystat":{"day_list":[{"year":2020,"month":4,"day":6,"energy_wh":17}],"err_code":0}}}
2020-04-06 22:18:37 DEBUG (SyncWorker_1) [pyHS100.protocol] > (66) {"smartlife.iot.common.emeter": {"get_monthstat": {"year": 2020}}}
2020-04-06 22:18:37 DEBUG (SyncWorker_1) [pyHS100.protocol] < (118) {"smartlife.iot.common.emeter":{"get_monthstat":{"month_list":[{"year":2020,"month":4,"energy_wh":17}],"err_code":0}}}

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

No wonder it has to retry all the time. Its being bombarded with api requests

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

Also makes 24 sysinfo api requests each restart

@rytilahti
Copy link
Member

rytilahti commented Apr 6, 2020

Yes, each property access of the bulb device (self.smartbulb.<anything> in

def get_light_state(self, light_features: LightFeatures) -> LightState:
) will cause a separate i/o request on the device.

That's one of the drivers for the new backend lib and this PR (the backend lib will simply cache the accesses to make it invisible for upstream users): #30719 - alas, its progress is currently stalled due to some necessary changes to support multiplug switches to avoid dropping support for those devices until I (or someone who wants to contribute) finds time to figure it all out.

@codecov
Copy link

codecov bot commented Apr 6, 2020

Codecov Report

Merging #33606 into dev will decrease coverage by 0.01%.
The diff coverage is 92.81%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev   #33606      +/-   ##
==========================================
- Coverage   94.76%   94.75%   -0.02%     
==========================================
  Files         780      858      +78     
  Lines       56315    60839    +4524     
==========================================
+ Hits        53368    57646    +4278     
- Misses       2947     3193     +246     
Impacted Files Coverage Δ
homeassistant/components/abode/cover.py 100.00% <ø> (ø)
homeassistant/components/abode/lock.py 100.00% <ø> (ø)
homeassistant/components/abode/sensor.py 97.50% <ø> (ø)
homeassistant/components/airvisual/const.py 100.00% <ø> (ø)
homeassistant/components/august/subscriber.py 76.00% <ø> (ø)
homeassistant/components/axis/binary_sensor.py 70.00% <0.00%> (ø)
homeassistant/components/androidtv/media_player.py 86.24% <31.57%> (-3.73%) ⬇️
homeassistant/components/abode/camera.py 66.00% <66.66%> (ø)
homeassistant/bootstrap.py 75.38% <80.00%> (-0.02%) ⬇️
homeassistant/components/august/activity.py 91.80% <83.33%> (ø)
... and 329 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 851c171...2852eb9. Read the comment docs.

@balloob
Copy link
Member Author

balloob commented Apr 6, 2020

@bdraco thanks for the comments. I've now converted it to int before we even pass it to LightState. Same with making sure color temp is set correctly in requested light state.

I think that the flaw here is that we create light state objects, but really only need to send the parameters we want to change. ie, to turn off a light we just need to call with {"on_off": 0}. Instead we create light state objects and pass them around. Now I see that the light state objects are used to optimistically update the state, but I think that they are unnecessarily coupled with sending the actual commands.

However, I also don't want to dig too much into this integration as I have better things to do. Really just wanted to make controlling it a little faster.

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

I've got it cleaned up a bit. No more timeout errors

@bdraco
Copy link
Member

bdraco commented Apr 6, 2020

Also every turn on is causing another update

@bdraco
Copy link
Member

bdraco commented Apr 7, 2020

I'm going to borrow a non-colored bulb for testing with. It won't be here till this later this week though so leaving Testing Required until I have a chance to try it

@bramkragten
Copy link
Member

I'm going to borrow a non-colored bulb for testing with. It won't be here till this later this week though so leaving Testing Required until I have a chance to try it

I have 2 bulbs (1 colored and 1 dimmable) and a switch in order, should arrive this week.

@rytilahti
Copy link
Member

Are you using UI or an automation to change the color temperature?
UI

Then there must be something wrong in the UI not following the given limits, I suppose... Or some change affected how it is being handled.

@bdraco
Copy link
Member

bdraco commented Apr 7, 2020

Are you using UI or an automation to change the color temperature?
UI

Then there must be something wrong in the UI not following the given limits, I suppose... Or some change affected how it is being handled.

I don't think its setting the constraints properly in your other branch.

Let's reserve this conversation for the new PR when you send it in. I'd prefer not to add unrelated comments here as its going to trigger notifications for everyone who has contributed to this.

@rytilahti
Copy link
Member

Fair enough, I'll not pollute this PR anymore, but the PR will still be #30719 . I will just re-open it and fix the open issues when I find some time for it. However, the logic behind those limits has not changed (see https://github.com/home-assistant/core/pull/30719/files#diff-9a900d2f83693dd3e01d2894bf1c6bffL266-L283 in get_light_features) so I'm not sure why it is not working. We can continue the discussion on missing parts /issues in that PR, too.

@bdraco
Copy link
Member

bdraco commented Apr 7, 2020

Fixed lights that do not support color

@bdraco
Copy link
Member

bdraco commented Apr 8, 2020

Screen Shot 2020-04-08 at 12 53 54 PM

working with the older bulbs as well

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEST PASS

@bdraco
Copy link
Member

bdraco commented Apr 8, 2020

I'm at the limit of what I can test. Let's wait for @bramkragten to get the devices in to validate this.

@bramkragten
Copy link
Member

I just got the devices, will test tonight

@bramkragten
Copy link
Member

bramkragten commented Apr 8, 2020

🎉 That's a nice speed improvement! Way more stable now. Let's merge this, and after that, we can look at the async version or improve this integration a little more (I noticed that we only discover devices at startup for instance)

@bdraco bdraco merged commit df744c5 into dev Apr 8, 2020
@delete-merged-branch delete-merged-branch bot deleted the speedup-tplink branch April 8, 2020 19:36
@balloob balloob added this to the 0.108.1 milestone Apr 8, 2020
@rytilahti
Copy link
Member

rytilahti commented Apr 8, 2020

Uhh, so, just a personal opinion, but if you really want to keep adding more hacky optimizations, I hope there'll be some leniency when reviewing that PR in the future. My plan is to simply ignore all the changes that has happened up to this PR, as I think otherwise doing a rebase will be such a waste of time and effort (assuming git rebase won't automatically handle these changes without extra effort).

Therefore I'm pleading that you avoid doing any more optimization before we can manage to finalize that port & cleanup PR, thanks.. To be honest, I feel quite saddened by the amount of effort (or lack thereof) what was put into handling this properly: that PR has been active since January and provides the proper fix (and some cleanups to get rid of unnecessary code) for this, but here we concentrate on hacking around it.

@bdraco
Copy link
Member

bdraco commented Apr 8, 2020

My plan is to simply ignore all the changes that has happened up to this PR, as I think otherwise doing a rebase will be such a waste of time and effort

I don't know the history here, but if you have solved the performance issue by converting to async (and adding the caching) it seems like you can dump most of the code in there and make this much simpler.

balloob added a commit that referenced this pull request Apr 9, 2020
* Speed up TP-Link lights

* Color temp kan be None

* hs as int, force color temp=0

* Fix color temp?

* Additional tplink cleanups to reduce api calls

* Update test to return state, remove Throttle

* Fix state restore on off/on

* Fix lights without hue/sat

Co-authored-by: J. Nick Koston <[email protected]>
@balloob balloob mentioned this pull request Apr 9, 2020
@ConsolesandCasks
Copy link

ConsolesandCasks commented Apr 9, 2020

this change broke my dimmers:

tplink: Error on device update!

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 324, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 476, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 254, in update
    self._light_state = self._get_light_state_retry()
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 314, in _get_light_state_retry
    return self._get_light_state()
  File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 360, in _get_light_state
    return self._light_state_from_params(self.smartbulb.get_light_state())
AttributeError: 'SmartPlug' object has no attribute 'get_light_state'

@bdraco
Copy link
Member

bdraco commented Apr 9, 2020

@garyalbert. What is the model number of the device with the issue?

@ConsolesandCasks
Copy link

@bdraco HS220 dimmers
I have 2 of these, 1 LB120, 1 HS105, and 1 HS200
Only the HS220s are having issues

@bdraco
Copy link
Member

bdraco commented Apr 9, 2020

@bdraco HS220 dimmers

I have 2 of these, 1 LB120, 1 HS105, and 1 HS200

Only the HS220s are having issues

Prime now had one in stock. I’ll fix it when it gets here later this afternoon

@MartinHjelmare
Copy link
Member

Please open an issue if you suspect a bug.

Merged PRs should not be used for support or bug reports. Thanks!

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Apr 9, 2020
@bdraco
Copy link
Member

bdraco commented Apr 9, 2020

@garyalbert Please open an issue here https://github.com/home-assistant/core/issues/new?template=BUG_REPORT.md and be sure to include your yaml config if any. Thank you!

@rytilahti
Copy link
Member

Here's the issue if someone comes looking for it: #33896

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants