FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Extend schedule handling cli support by yparitcher · Pull Request #501 · python-kasa/python-kasa · GitHub

Repository navigation

Extend schedule handling cli support - #501

Closed
yparitcher wants to merge 17 commits into
python-kasa:masterfrom
yparitcher:schedule
Closed

yparitcher wants to merge 17 commits into
python-kasa:masterfrom
yparitcher:schedule

Conversation

yparitcher commented Aug 25, 2023 •
edited
Loading

Copy link
Copy Markdown

Some improvements for the schedule command.

A draft for now, I plan on adding rule edit support, please give feedback

Fixes: #265
Fixes: #436

Based on the commands in the Thesis linked in that issue.
Tested on a EP10

yparitcher marked this pull request as draft August 25, 2023 03:01

codecov-commenter commented Aug 25, 2023 •
edited by codecov Bot
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.97297% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.13%. Comparing base (24da24e) to head (d90bf19).
⚠️ Report is 755 commits behind head on master.

Files with missing lines Patch % Lines
kasa/cli.py 58.33% 35 Missing ⚠️
kasa/modules/rulemodule.py 93.61% 3 Missing ⚠️
kasa/modules/time.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #501      +/-   ##
==========================================
- Coverage   79.59%   78.13%   -1.47%     
==========================================
  Files          26       26              
  Lines        1960     2108     +148     
  Branches      602      673      +71     
==========================================
+ Hits         1560     1647      +87     
- Misses        359      419      +60     
- Partials       41       42       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

rytilahti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the PR @yparitcher! I added some initial review comments below.

Comment thread kasa/cli.py

@schedule.command(name="list")
@pass_dev
@click.option("--json", is_flag=True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

jsonifying is handled on the cli automatically for the return value, so there should be no need for special handling.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This way i get the actual json that is passed to the device, not the python rule wrapped in json

$ kasa --host 192.168.0.xxx --type plug schedule list
id='B9A82B5BA5AB6F6DA4277429A226D632' name='7 Off 11 On' enable=<EnabledOption.Enabled: 1> wday=[1, 1, 1, 1, 1, 1, 1] repeat=<EnabledOption.Enabled: 1> sact=<Action.TurnOff: 0> stime_opt=<TimeOption.Enabled: 0> smin=420 eact=<Action.TurnOn: 1> etime_opt=<TimeOption.Enabled: 0> emin=660 s_light=None

$ kasa --host 192.168.0.xxx --type plug --json schedule list
id='B9A82B5BA5AB6F6DA4277429A226D632' name='7 Off 11 On' enable=<EnabledOption.Enabled: 1> wday=[1, 1, 1, 1, 1, 1, 1] repeat=<EnabledOption.Enabled: 1> sact=<Action.TurnOff: 0> stime_opt=<TimeOption.Enabled: 0> smin=420 eact=<Action.TurnOn: 1> etime_opt=<TimeOption.Enabled: 0> emin=660 s_light=None
[
    "id='B9A82B5BA5AB6F6DA4277429A226D632' name='7 Off 11 On' enable=<EnabledOption.Enabled: 1> wday=[1, 1, 1, 1, 1, 1, 1] repeat=<EnabledOption.Enabled: 1> sact=<Action.TurnOff: 0> stime_opt=<TimeOption.Enabled: 0> smin=420 eact=<Action.TurnOn: 1> etime_opt=<TimeOption.Enabled: 0> emin=660 s_light=None"
]

$ kasa --host 192.168.0.xxx --type plug schedule list --json
{"id": "B9A82B5BA5AB6F6DA4277429A226D632", "name": "7 Off 11 On", "enable": 1, "wday": [1, 1, 1, 1, 1, 1, 1], "repeat": 1, "sact": 0, "stime_opt": 0, "smin": 420, "eact": 1, "etime_opt": 0, "emin": 660, "s_light": null}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This needs to be fixed separately then (I think the proper way would be extending the json_formatter_cb by defining a serializer for pydantic BaseModel), but let's do that in a separate PR.

Comment thread kasa/modules/rulemodule.py Outdated
Comment thread kasa/cli.py Outdated
Comment thread kasa/cli.py Outdated
Comment on lines +664 to +670
@click.option("--wday", type=str, required=True)
@click.option("--sact", type=click.IntRange(-1, 2), default=None, required=True)
@click.option("--stime_opt", type=click.IntRange(-1, 2), default=None, required=True)
@click.option("--smin", type=click.IntRange(0, 1440), default=None, required=True)
@click.option("--eact", type=click.IntRange(-1, 2), default=-1)
@click.option("--etime_opt", type=click.IntRange(-1, 2), default=-1)
@click.option("--emin", type=click.IntRange(0, 1440), default=None)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think we should modiy the Rule to have more user-friendly field names (using alias) and add some documentation on what input values they accept.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I changed the names (If you better ones please comment), the doc still needs to be done.

Is there a way to pass the pydatic info to click? for example TimeOption

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't have a direct answer to that, sorry. I suppose generic support for all pydantic models is not that easy, but one can use manually inherit from click.ParamType to perform the conversion.

Comment thread kasa/cli.py
if name is not None:
rule_to_edit.name = name
if enable is not None:
rule_to_edit.enable = 1 if enable else 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

pydantic should handle the conversion just fine as long as the types are correct, so there should be no need for manual conversions here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I want that only the user specified options should override the existing rule fields, however if the user does not specify a flag we get a None value that i don't want to pass to pydantic to overwrite the field. If there is a better way to do this with click & pydantic please let me know. (I am not too familiar with either of them)

rytilahti added the enhancement New feature or request label Aug 26, 2023
rytilahti changed the title Schedule Extend schedule handling cli support Aug 26, 2023

Copy link
Copy Markdown
Author

As i do not have bulbs, I did not implement bulb specific functionality, but i did leave the scaffolding for someone else to do it.

Copy link
Copy Markdown
Author

I redid the rule inheritance a bit. not sure if there is a better way

yparitcher marked this pull request as ready for review August 27, 2023 04:01

rytilahti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I saw that you extend the time module to support timezone handling, could you please move that into its own PR to keep it easier to review? I'll try to find some time soon to take another look at this, alas, I won't be able to test this until some point next month.

sact: Optional[Action]
stime_opt: TimeOption
smin: int
sact: Optional[Action] = Field(alias="start_action")

rytilahti Aug 27, 2023 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
sact: Optional[Action] = Field(alias="start_action")
start_action: Optional[Action] = Field(alias="sact")

This is wrong way around, no? Basically, the alias allows using a nicer name for the field name itself, reading (and serializing?) in this case from/to a json field called sact.

Copy link
Copy Markdown
Author

I don't have much time to work on this (it was a bit driveby, as it now work for me locally). But i hope to eventually split out the changes into separate PRs. Anyone is also welcome to fixup this PR if wanted

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

github-actions Bot added stale and removed stale labels Sep 28, 2024
sdb9696 added the stale label Oct 1, 2024
github-actions Bot removed the stale label Oct 2, 2024

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

github-actions Bot added stale and removed stale labels Dec 31, 2024

github-actions Bot commented Apr 1, 2025

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

github-actions Bot added stale and removed stale labels Apr 1, 2025

github-actions Bot commented Jul 1, 2025

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

github-actions Bot added stale and removed stale labels Jul 1, 2025

github-actions Bot commented Oct 1, 2025

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

github-actions Bot added stale and removed stale labels Oct 1, 2025

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

github-actions Bot added stale and removed stale labels Dec 31, 2025

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

github-actions Bot added stale and removed stale labels Apr 1, 2026
yparitcher closed this Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Add support for setting the timezone Set schedules?

4 participants


Back | FazBrowse Home | New Git URL