Skip to content

Conversation

@connorproctor
Copy link
Contributor

@connorproctor connorproctor commented Jun 7, 2020

  • Adds a transition param to set_brightness() that specifies the duration in milliseconds that the dimmer switch will take to transition to the new brightness

This is a stab at the first part of #44.

Closes #44

@connorproctor connorproctor force-pushed the feature/hs220-transition-support branch from 6205b84 to 319b510 Compare June 8, 2020 02:39
@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2020

Codecov Report

Merging #69 into master will decrease coverage by 0.67%.
The diff coverage is 30.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #69      +/-   ##
==========================================
- Coverage   62.00%   61.33%   -0.68%     
==========================================
  Files           9        9              
  Lines        1145     1169      +24     
  Branches      169      177       +8     
==========================================
+ Hits          710      717       +7     
- Misses        398      411      +13     
- Partials       37       41       +4     
Impacted Files Coverage Δ
kasa/smartdimmer.py 56.89% <30.00%> (-19.58%) ⬇️

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 9dc0cba...6eaa318. Read the comment docs.

@kirichkov
Copy link
Contributor

Thanks for your contribution! Can you please add some test cases so we don't break this functionality by mistake in the future?

Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the PR! Just a couple of minor changes (besides adding some tests) are needed.

@rytilahti
Copy link
Member

rytilahti commented Jun 8, 2020

@connorproctor to give you an idea about how to test that the methods are being called properly using the transition (and without), check out the linked PR.

edit: btw, does the transitions also work for turn_on and turn_off somehow?

@connorproctor
Copy link
Contributor Author

btw, does the transitions also work for turn_on and turn_off somehow?

I'm not aware of a way of passing a transition duration to the switch when using set_relay_state via self._query_helper("system", "set_relay_state", {"state": 1}). Though I think it should be possible to use set_dimmer_transition from turn_on and turn_off with the brightness value set to the current brightness() or 0, respectively.

@connorproctor
Copy link
Contributor Author

connorproctor commented Jun 11, 2020

I'm trying to write tests but when running them on my computer all the async tests are skipped.

I'm getting this error:

async def functions are not natively supported and have been skipped.
You need to install a suitable plugin for your async framework, for example:
  - pytest-asyncio
  - pytest-trio
  - pytest-tornasync
  - pytest-twisted

However I do have pytest-asyncio installed.

Any ideas for how to get the tests running?

@rytilahti
Copy link
Member

That's really odd and I'm afraid I don't have any direct answer for that. Using poetry should create a working dev environment (including the necessary libs for testing, such as pytest-asyncio), but as you have it installed, I'm not really sure what is going on...

When you execute pytest kasa/, which plugins are you seeing in the list? Here's what I have (in a modified environment: plugins: aiohttp-0.3.0, azurepipelines-0.8.0, requests-mock-1.7.0, anyio-1.3.1, asyncio-0.11.0, timeout-1.3.3, sugar-0.9.3, forked-1.1.3, pylint-0.14.1, cov-2.9.0, mock-3.1.1, xdist-1.32.0). I think the asyncio-0.11.0 is for pytest-asyncio here.

@connorproctor
Copy link
Contributor Author

connorproctor commented Jun 12, 2020

With a fresh poetry environment these were my pytest plugins when running poetry run pytest kasa/:
plugins: azurepipelines-0.8.0, cov-2.9.0, mock-3.1.1, sugar-0.9.3, anyio-1.3.1, asyncio-0.11.0.

I manually installed all the plugins you have listed and now most of the tests run. Thanks for the help. This is my first time using poetry, so I'm not sure where the problem is, but I imagine there's a missing dependency or two.

@connorproctor connorproctor force-pushed the feature/hs220-transition-support branch from 319b510 to a5c180f Compare June 12, 2020 04:12
@connorproctor connorproctor requested a review from rytilahti June 12, 2020 04:13
@rytilahti
Copy link
Member

Doing poetry install should create automatically a working environment (that can be accessed using poetry run), so there should be no need for manual installations.. Glad you got it working though!

Anyway, in case you had already activated virtualenv, the install will also use that (that's how I have my own dev setup).

@connorproctor connorproctor force-pushed the feature/hs220-transition-support branch 2 times, most recently from 224b311 to 152c7a7 Compare June 12, 2020 16:11
@connorproctor
Copy link
Contributor Author

connorproctor commented Jun 12, 2020

I'm not sure if it's something weird with my local setup or not, but it looks like the missing dependency that fixed the tests was pytest-aiohttp. To verify I: deleted the virtual environment, did a fresh poetry install, ran poetry run pytest to verify tests were broken, ran poetry run pip install pytest-aiohttp, reran poetry run pytest to verify that most tests were now working.

I updated the tests, let me know what you think.

@rytilahti
Copy link
Member

I'm not sure if it's something weird with my local setup or not, but it looks like the missing dependency that fixed the tests was pytest-aiohttp. To verify I: deleted the virtual environment, did a fresh poetry install, ran poetry run pytest to verify tests were broken, ran poetry run pip install pytest-aiohttp, reran poetry run pytest to verify that most tests were now working.

Indeed, I did also check that out and looks like it is not working, and the same thing also happens on CI for other python versions than what I have locally (3.8), but as it's a warning I never noticed that...

This is really odd, I'm curious what causes it to work when installing pytest-aiohttp (which I confirmed is the case)? As we are not using aiohttp in this library, adding its pytest plugin as a dependency feels wrong. A short googling reveals this pytest-dev/pytest#7144 but we are not really using unittest here, either..

* Adds a transition param to set_brightness(), turn_on(), and turn_off() that specifies the duration in milliseconds that the dimmer switch will take to transition to the new state.
* Fixes bug where set_brightness(0) was allowed even though the dimmer does not support it. Now brightness values of 0 are coerced to 1 to be consistent with bulbs (which do support brightness values of 0).
@connorproctor connorproctor force-pushed the feature/hs220-transition-support branch from 152c7a7 to 6eaa318 Compare June 13, 2020 22:55
Copy link
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks go to go, thanks! 👍 I'm only confused why this does not trigger a mypy error like my PR did..

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve HS220 support

4 participants