8000 Add support for json output by rytilahti · Pull Request #430 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Add support for json output #430

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

Merged
merged 4 commits into from
Feb 18, 2023
Merged

Conversation

rytilahti
Copy link
Member
@rytilahti rytilahti commented Feb 18, 2023

Passing --json will now suppress the standard output and provides JSON output,
which is command-dependent:

  • Commands that act directly on the device will return the raw device response as-is.
  • Commands that return just a parsed format of some specific information (like time) will return just that information.

The likely most useful usecase is just dumping the whole device state for further processing, which can be done by using using kasa --json --host 192.168.xx.xx state:

❯ kasa --json --host 192.168.250.188 state|jq 'map_values(keys)'
{
  "system": [
    "get_sysinfo"
  ],
  "schedule": [
    "get_daystat",
    "get_monthstat",
    "get_next_action",
    "get_realtime",
    "get_rules"
  ],
  "anti_theft": [
    "get_next_action",
    "get_rules"
  ],
  "time": [
    "get_time",
    "get_timezone"
  ],
  "cnCloud": [
    "get_info"
  ],
  "emeter": [
    "get_daystat",
    "get_monthstat",
    "get_realtime"
  ]
}

Fixes #209
Obsoletes #258

Passing --json will now suppress the standard output and provide a JSON output.
@rytilahti rytilahti added the enhancement New feature or request label Feb 18, 2023
@rytilahti rytilahti added this to the 0.5.1 milestone Feb 18, 2023
@codecov-commenter
Copy link
codecov-commenter commented Feb 18, 2023

Codecov Report

Base: 78.95% // Head: 79.80% // Increases project coverage by +0.85% 🎉

Coverage data is based on head (1b26b8d) compared to base (12c98eb).
Patch coverage: 50.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #430      +/-   ##
==========================================
+ Coverage   78.95%   79.80%   +0.85%     
==========================================
  Files          25       25              
  Lines        1863     1892      +29     
  Branches      269      268       -1     
==========================================
+ Hits         1471     1510      +39     
+ Misses        358      342      -16     
- Partials       34       40       +6     
Impacted Files Coverage Δ
kasa/cli.py 56.30% <50.00%> (+3.55%) ⬆️
kasa/modules/usage.py 69.64% <0.00%> (-4.17%) ⬇️
kasa/smartbulb.py 92.27% <0.00%> (ø)
kasa/modules/emeter.py 97.77% <0.00%> (+0.15%) ⬆️
kasa/smartdevice.py 86.93% <0.00%> (+2.76%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rytilahti rytilahti changed the title Add json support Add support for json output Feb 18, 2023
@rytilahti rytilahti merged commit 016f4df into python-kasa:master Feb 18, 2023
@rytilahti rytilahti deleted the feat/json_output branch February 18, 2023 20:41
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 machine-readable output
2 participants
0