Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for lightstrips (KL430) #74

Merged
merged 10 commits into from
Jul 19, 2020

Conversation

rytilahti
Copy link
Member

@rytilahti rytilahti commented Jun 20, 2020

Initial PR to add support for KL430 and other light strips (if any). The API looks similar to smart bulb, only difference being a different service name.

kasa --ledstrip --host <host> can be used for testing.

TBD:

  • Tests
  • Discovery support

Closes #67.

Copy link
Contributor

@kirichkov kirichkov left a comment

Choose a reason for hiding this comment

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

Loogs good to me

@rytilahti rytilahti marked this pull request as draft June 23, 2020 15:00
@rytilahti
Copy link
Member Author

Thanks for the review, this is merely a draft until we get someone to test it. The commands can then be cleaned up prior the merge :-)

@CursedDog19
Copy link

I have a light strip but how do I test this? Where do I run "kasa --ledstrip --host " ?

@rytilahti
Copy link
Member Author

The simplest way is to do the following:

  1. Clone the repository:
git clone https://github.com/rytilahti/python-kasa.git
  1. Change to the branch used for this PR:
git checkout feature/add_smartstrip
  1. Install it (this will automatically create a virtual environment and install the dependencies etc.):
poetry install
  1. Run the command inside poetry created virtual environment:
poetry run kasa --ledstrip --host <ip address> state

@CursedDog19
Copy link

The simplest way is to do the following:

  1. Clone the repository:
git clone https://github.com/rytilahti/python-kasa.git
  1. Change to the branch used for this PR:
git checkout feature/add_smartstrip
  1. Install it (this will automatically create a virtual environment and install the dependencies etc.):
poetry install
  1. Run the command inside poetry created virtual environment:
poetry run kasa --ledstrip --host <ip address> state

I've installed poetry but I still can't run "poetry install". How do I set up poetry?

@CursedDog19
Copy link

CursedDog19 commented Jun 29, 2020

Update: I installed the dependencies with pip and now I am getting the following error message after running "python kasa" from the python-kasa directory:
can't find main module in 'kasa'

@rytilahti
Copy link
Member Author

rytilahti commented Jun 30, 2020

https://python-poetry.org/docs/#installation has the installation instructions for poetry, that's the simplest way to make sure your environment is correctly set. However, if you managed to install it manually, that is also fine. The command is kasa, not python kasa (which tries to execute a python script with the name of kasa), so that's the reason for the error.

@CursedDog19
Copy link

CursedDog19 commented Jun 30, 2020 via email

@rytilahti
Copy link
Member Author

That's really odd, as the page says this:

The installer installs the poetry tool to Poetry's bin directory. On Unix it is located at $HOME/.poetry/bin and on Windows at %USERPROFILE%.poetry\bin.

This directory will be in your $PATH environment variable, which means you can run them from the shell without further configuration.

As far as I know, the install command cannot be executed outside the source tree, but you could try to modify the PATH (https://stackoverflow.com/a/1333717 is perhaps relevant) to add poetry's bin directory to it. Or you could always simply execute the command using the whole path like %USERPROFILE%\.poetry\bin\poetry install and so on.

@rytilahti rytilahti mentioned this pull request Jul 2, 2020
@darkoppressor
Copy link
Contributor

darkoppressor commented Jul 19, 2020

OK, I have one of these KL430 light strips and I am versed in Python but don't know anything about Poetry (or anything Home Assistant aside from being a user). I have followed the instructions above (I didn't edit cli.py) and believe I have it all setup correctly. When I run 'poetry run kasa --ledstrip --host state', I get this result:

Using python3.8 (3.8.0)
== Pantry lights - KL430(US) ==
Host: 192.168.1.145
Device state: ON

== Generic information ==
Time:         None
Hardware:     1.0
Software:     1.0.10 Build 200522 Rel.104340
MAC (rssi):   cc:32:e5:23:0f:55 (-53)
Location:     {'latitude': 429705, 'longitude': -859256}

== Device specific information ==

Traceback (most recent call last):
File "", line 1, in
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 799, in call
return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/init.py", line 72, in run
return asynclib.run(func, *args, **backend_options) # type: ignore
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 114, in run
raise exception
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 76, in wrapper
retval = await func(*args)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 802, in _main
return await main(*args, **kwargs)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 748, in main
rv = await self.invoke(ctx)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 1175, in invoke
return await _process_result(await sub_ctx.command.invoke(sub_ctx))
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 994, in invoke
return await ctx.invoke(self.callback, **ctx.params)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/python-kasa/kasa/cli.py", line 257, in state
for k, v in dev.state_information.items():
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 115, in wrapped
return f(*args, **kwargs)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 281, in state_information
info["Valid temperature range"] = self.valid_temperature_range
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 115, in wrapped
return f(*args, **kwargs)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 118, in valid_temperature_range
raise SmartDeviceException(
kasa.exceptions.SmartDeviceException: Unknown color temperature range, please open an issue on github

I will continue poking at it.

@darkoppressor
Copy link
Contributor

darkoppressor commented Jul 19, 2020

OK looks like smartbulb.py's TPLINK_KELVIN is missing a value for the KL430. According to the tech specs at https://www.kasasmart.com/us/products/smart-lighting/kasa-smart-led-light-strip-kl430, the color temperature range for the KL430 is 2500K to 9000K, so I added the KL430 to TPLINK_KELVIN using those values. Specifically I added 'r"KL430(US)": (2500, 9000),' below line 19 in smartbulb.py.

Now I get this:

Using python3.8 (3.8.0)
== Pantry lights - KL430(US) ==
Host: 192.168.1.145
Device state: ON

== Generic information ==
Time:         None
Hardware:     1.0
Software:     1.0.10 Build 200522 Rel.104340
MAC (rssi):   cc:32:e5:23:0f:55 (-51)
Location:     {'latitude': 429705, 'longitude': -859256}

== Device specific information ==
Brightness: 100
Is dimmable: True
Color temperature: 3500
Valid temperature range: (2500, 9000)
HSV: (0, 0, 100)


== Current State ==
{'voltage_mv': 0, 'current_ma': 0, 'power_mw': 16826, 'total_wh': 683, 'err_code': 0}

Is there more I can do to test this? What is needed?

@rytilahti
Copy link
Member Author

rytilahti commented Jul 19, 2020

Thanks for testing and figuring out how to get it working, I'll adapt the PR based on your feedback!

Could you check out if the commands are working correctly (on, off, hsv, temperature, etc.)? Are there some other locally controllable features that should be added?

Also, it'd be great if you could contribute a fixture file (running `kasa dump-discover) for the unit tests (and for discovery). You could create a PR on top of this PR, then I can also add it to the test suite.

* Use lightstrip instead of {led,light}strip consistently everywhere
* The cli flag is now --lightstrip
@python-kasa python-kasa deleted a comment from codecov-commenter Jul 19, 2020
@codecov-commenter
Copy link

codecov-commenter commented Jul 19, 2020

Codecov Report

Merging #74 into master will increase coverage by 0.48%.
The diff coverage is 87.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #74      +/-   ##
==========================================
+ Coverage   72.37%   72.86%   +0.48%     
==========================================
  Files           9       10       +1     
  Lines        1191     1227      +36     
  Branches      182      185       +3     
==========================================
+ Hits          862      894      +32     
- Misses        296      299       +3     
- Partials       33       34       +1     
Impacted Files Coverage Δ
kasa/cli.py 53.84% <50.00%> (-0.20%) ⬇️
kasa/discover.py 41.22% <60.00%> (+0.86%) ⬆️
kasa/smartbulb.py 94.28% <100.00%> (+0.04%) ⬆️
kasa/smartdevice.py 82.73% <100.00%> (+0.20%) ⬆️
kasa/smartlightstrip.py 100.00% <100.00%> (ø)

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 0edbb43...6b7b63e. Read the comment docs.

Signed-off-by: Kevin Wells <darkoppressor@gmail.com>
@darkoppressor
Copy link
Contributor

darkoppressor commented Jul 19, 2020

OK, I submitted a PR for adding a fixture file for the KL430. @rytilahti, the PR is for merging my change to your fork. Let me know if that is the wrong way to do that, I've never actually done a PR on GitHub before...

As for testing the commands:
alias: working
brightness: can get, cannot set:

Setting brightness to 25
Traceback (most recent call last):
File "", line 1, in
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 799, in call
return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/init.py", line 72, in run
return asynclib.run(func, *args, **backend_options) # type: ignore
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 114, in run
raise exception
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 76, in wrapper
retval = await func(*args)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 802, in _main
return await main(*args, **kwargs)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 748, in main
rv = await self.invoke(ctx)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 1175, in invoke
return await _process_result(await sub_ctx.command.invoke(sub_ctx))
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 994, in invoke
return await ctx.invoke(self.callback, **ctx.params)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/python-kasa/kasa/cli.py", line 361, in brightness
click.echo(await dev.set_brightness(brightness, transition=transition))
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 104, in wrapped
return await f(*args, **kwargs)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 317, in set_brightness
return await self.set_light_state(light_state, transition=transition)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 194, in set_light_state
light_state = await self._query_helper(
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 272, in _query_helper
raise SmartDeviceException(f"Error on {target} {cmd}: {result}")
kasa.exceptions.SmartDeviceException: Error on smartlife.iot.lightStrip transition_light_state: {'err_code': -2, 'err_msg': 'member not support'}

discover: working
dump-discover: working
emeter: working
hsv: can get, cannot set:

Setting HSV: 0 0 50
Traceback (most recent call last):
File "", line 1, in
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 799, in call
return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/init.py", line 72, in run
return asynclib.run(func, *args, **backend_options) # type: ignore
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 114, in run
raise exception
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 76, in wrapper
retval = await func(*args)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 802, in _main
return await main(*args, **kwargs)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 748, in main
rv = await self.invoke(ctx)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 1175, in invoke
return await _process_result(await sub_ctx.command.invoke(sub_ctx))
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 994, in invoke
return await ctx.invoke(self.callback, **ctx.params)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/python-kasa/kasa/cli.py", line 404, in hsv
click.echo(await dev.set_hsv(h, s, v, transition=transition))
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 104, in wrapped
return await f(*args, **kwargs)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 257, in set_hsv
return await self.set_light_state(light_state, transition=transition)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 194, in set_light_state
light_state = await self._query_helper(
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 272, in _query_helper
raise SmartDeviceException(f"Error on {target} {cmd}: {result}")
kasa.exceptions.SmartDeviceException: Error on smartlife.iot.lightStrip transition_light_state: {'err_code': -2, 'err_msg': 'member not support'}

led: working (correctly doesn't work since this is not a plug...)
off: not working:

Turning off Pantry lights
Traceback (most recent call last):
File "", line 1, in
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 799, in call
return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/init.py", line 72, in run
return asynclib.run(func, *args, **backend_options) # type: ignore
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 114, in run
raise exception
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 76, in wrapper
retval = await func(*args)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 802, in _main
return await main(*args, **kwargs)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 748, in main
rv = await self.invoke(ctx)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 1175, in invoke
return await _process_result(await sub_ctx.command.invoke(sub_ctx))
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 994, in invoke
return await ctx.invoke(self.callback, **ctx.params)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/python-kasa/kasa/cli.py", line 468, in off
await dev.turn_off(transition=transition)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 347, in turn_off
return await self.set_light_state({"on_off": 0}, transition=transition)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 194, in set_light_state
light_state = await self._query_helper(
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 272, in _query_helper
raise SmartDeviceException(f"Error on {target} {cmd}: {result}")
kasa.exceptions.SmartDeviceException: Error on smartlife.iot.lightStrip transition_light_state: {'err_code': -2, 'err_msg': 'member not support'}

on: not working:

Turning on Pantry lights
Traceback (most recent call last):
File "", line 1, in
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 799, in call
return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/init.py", line 72, in run
return asynclib.run(func, *args, **backend_options) # type: ignore
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 114, in run
raise exception
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 76, in wrapper
retval = await func(*args)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 802, in _main
return await main(*args, **kwargs)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 748, in main
rv = await self.invoke(ctx)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 1175, in invoke
return await _process_result(await sub_ctx.command.invoke(sub_ctx))
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 994, in invoke
return await ctx.invoke(self.callback, **ctx.params)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/python-kasa/kasa/cli.py", line 446, in on
await dev.turn_on(transition=transition)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 354, in turn_on
return await self.set_light_state({"on_off": 1}, transition=transition)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 194, in set_light_state
light_state = await self._query_helper(
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 272, in _query_helper
raise SmartDeviceException(f"Error on {target} {cmd}: {result}")
kasa.exceptions.SmartDeviceException: Error on smartlife.iot.lightStrip transition_light_state: {'err_code': -2, 'err_msg': 'member not support'}

raw-command: did not test because I wasn't sure how
reboot: working
state: working as per above
sysinfo: working
temperature: can get, cannot set:

Setting color temperature to 3500
Traceback (most recent call last):
File "", line 1, in
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 799, in call
return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/init.py", line 72, in run
return asynclib.run(func, *args, **backend_options) # type: ignore
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 114, in run
raise exception
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 76, in wrapper
retval = await func(*args)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 802, in _main
return await main(*args, **kwargs)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 748, in main
rv = await self.invoke(ctx)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 1175, in invoke
return await _process_result(await sub_ctx.command.invoke(sub_ctx))
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 994, in invoke
return await ctx.invoke(self.callback, **ctx.params)
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/.cache/pypoetry/virtualenvs/python-kasa-KWNvepjh-py3.8/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
rv = await rv
File "/home/kevin/python-kasa/kasa/cli.py", line 385, in temperature
await dev.set_color_temp(temperature, transition=transition)
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 104, in wrapped
return await f(*args, **kwargs)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 292, in set_color_temp
return await self.set_light_state(light_state, transition=transition)
File "/home/kevin/python-kasa/kasa/smartbulb.py", line 194, in set_light_state
light_state = await self._query_helper(
File "/home/kevin/python-kasa/kasa/smartdevice.py", line 272, in _query_helper
raise SmartDeviceException(f"Error on {target} {cmd}: {result}")
kasa.exceptions.SmartDeviceException: Error on smartlife.iot.lightStrip transition_light_state: {'err_code': -2, 'err_msg': 'member not support'}

time: returns an empty string, but I assume that is OK because I don't think this thing has a clock
wifi: did not test because I wasn't sure how

@rytilahti
Copy link
Member Author

rytilahti commented Jul 19, 2020

Merged the fixture file, thanks! And thanks a lot for doing so thorough testing on it :-)

So, looks like the sysinfo is the only thing that is working currently. You could manually modify the __init__ of the strip to change the method name like here: af7245c#diff-3845d16a3d7b99072959f9bc01cb7f72R16

Or try this raw command:

kasa raw-command smartlife.iot.lightStrip set_light_state '{"brightness": 100}'

(or color_temp, or hue+saturation combination like done in smartbulb).

Another way to figure the API out would be to sniff the traffic from the app, and use the parse_pcap script contained in devtools in this repository. But if set_light_state works, I think we have basic support for this device without resorting to that.

@darkoppressor
Copy link
Contributor

OK, testing using the raw command method you outlined:

brightness: working

poetry run kasa --lightstrip --host 192.168.1.145 raw-command smartlife.iot.lightStrip set_light_state '{"brightness": 25}'

hsv: working

poetry run kasa --lightstrip --host 192.168.1.145 raw-command smartlife.iot.lightStrip set_light_state '{"hue": 240, "saturation": 100, "brightness": 100}'

off: working

poetry run kasa --lightstrip --host 192.168.1.145 raw-command smartlife.iot.lightStrip set_light_state '{"on_off": 0}'

on: working

poetry run kasa --lightstrip --host 192.168.1.145 raw-command smartlife.iot.lightStrip set_light_state '{"on_off": 1}'

temperature: working

poetry run kasa --lightstrip --host 192.168.1.145 raw-command smartlife.iot.lightStrip set_light_state '{"color_temp": 4000}'

@rytilahti
Copy link
Member Author

Great! I just pushed the set_light_state back, so only tests are missing and then this can be merged.

@rytilahti rytilahti marked this pull request as ready for review July 19, 2020 20:13
@rytilahti rytilahti changed the title Preliminary support for light strips Add support for lightstrips (KL430) Jul 19, 2020
@rytilahti rytilahti added the enhancement New feature or request label Jul 19, 2020
@rytilahti rytilahti merged commit d30d00a into python-kasa:master Jul 19, 2020
@rytilahti rytilahti deleted the feature/add_smartstrip branch July 19, 2020 20:32
@rytilahti rytilahti mentioned this pull request Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KL430 support
5 participants