Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.0 code, requirements and a basic readme
- Loading branch information
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
**This project is just a wrapper for the brilliant work done in [pyHS100](https://github.com/GadgetReactor/pyHS100).** | ||
|
||
**Supported devices** | ||
|
||
* Plugs | ||
* HS100 | ||
* HS103 | ||
* HS105 | ||
* HS110 | ||
|
||
# Usage | ||
|
||
### Discovery Only | ||
|
||
Don't provide any options to run a discovery scan for Kasa smartplugs and their LED status: | ||
|
||
``` | ||
> python kasa-dark-mode.py | ||
Plug Alias: Fan | ||
Current LED state: False | ||
--- | ||
Plug Alias: Network | ||
Current LED state: False | ||
--- | ||
``` | ||
|
||
### One for all | ||
|
||
Use `-l` or `-d` to set light (LED on) or dark (LED off) mode for all discovered Kasa smartplugs: | ||
|
||
``` | ||
> python kasa-dark-mode.py -d | ||
Plug Alias: Fan | ||
Current LED state: True | ||
New LED state: False | ||
--- | ||
Plug Alias: Network | ||
Current LED state: True | ||
New LED state: False | ||
``` | ||
|
||
### Interactive mode (`-i`, `--interactive`) | ||
|
||
Use interactive mode to toggle LED status lights for each discovered Kasa Plug: | ||
|
||
``` | ||
> python kasa-dark-mode.py -i | ||
You have selected interactive mode | ||
Searching for smartplugs... | ||
--plug found-- | ||
Plug Alias: Fan | ||
Current LED state: False | ||
Do you wish to turn ON 'Fan' LED [Y/n]: n | ||
--- | ||
--plug found-- | ||
Plug Alias: Network | ||
Current LED state: True | ||
Do you wish to turn OFF 'Network' LED [Y/n]: | ||
New LED state: False | ||
--- | ||
``` | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
from pyHS100 import Discover | ||
import sys | ||
import time | ||
import argparse | ||
|
||
def main(argv): | ||
# set up arg parser and arguments | ||
parser = argparse.ArgumentParser(prog='python3 btlegeiger.py', description='A Python Tool to Detect BTLE Beacons') | ||
parser.add_argument('--debug', default=False, action='store_true', help='Enable debug mode') | ||
parser.add_argument('-d', '--dark', default=False, action='store_true', help='Turn off smartplug LEDs') | ||
parser.add_argument('-l', '--light', default=False, action='store_true', help='Turn on smartplug LEDs') | ||
parser.add_argument('-i', '--interactive', default=False, action='store_true', help='Control smartplug LEDs interactively') | ||
args = parser.parse_args() | ||
|
||
if args.debug: | ||
print("Debug mode enabled") | ||
answer = query_yes_no("Is this working?", "yes") | ||
print(answer) | ||
|
||
if not args.interactive: | ||
options_mode(args) | ||
else: | ||
interactive_mode(args) | ||
|
||
|
||
def interactive_mode(args): | ||
print("You have selected interactive mode\nSearching for smartplugs...") | ||
for plug in Discover.discover().values(): | ||
if "SmartPlug" in str(plug): | ||
print("--plug found--") | ||
LEDstate = plug.led | ||
plugAlias = plug.alias | ||
print("Plug Alias: %s" % plugAlias) | ||
print("Current LED state: %s" % LEDstate) | ||
if LEDstate == True: #LED is on | ||
question = ("Do you wish to turn OFF '%s' LED" % plugAlias) | ||
answer = query_yes_no(question, "yes") | ||
if answer: | ||
plug.led = False # turn off LED | ||
print("New LED state: %s" % plug.led) | ||
elif LEDstate == False: #LED is off | ||
question = ("Do you wish to turn ON '%s' LED" % plugAlias) | ||
answer = query_yes_no(question, "yes") | ||
if answer: | ||
plug.led = True # turn on LED | ||
print("New LED state: %s" % plug.led) | ||
print("---") | ||
|
||
|
||
def options_mode(args): | ||
for plug in Discover.discover().values(): | ||
if "SmartPlug" in str(plug): | ||
print("Plug Alias: %s" % plug.alias) | ||
LEDstate = plug.led | ||
print("Current LED state: %s" % LEDstate) | ||
if args.dark: | ||
if not args.light: #check for conflicting otptions | ||
if LEDstate == True: #check for current LED state | ||
plug.led = False # turn off LED | ||
print("New LED state: %s" % plug.led) | ||
else: | ||
print("Lights are already off, skipping dark mode action") | ||
else: | ||
print("light and dark mode options selected - you can only choose 1") | ||
print("---") | ||
continue | ||
if args.light: | ||
if not args.dark: #check for conflicting otptions | ||
if LEDstate == False: | ||
plug.led = True # turn on LED | ||
print("New LED state: %s" % plug.led) | ||
else: | ||
print("Lights are already on, skipping light mode action") | ||
else: | ||
print("light and dark mode options selected - you can only choose 1") | ||
print("---") | ||
continue | ||
print("---") | ||
|
||
|
||
def query_yes_no(question, default="yes"): | ||
valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} | ||
if default is None: | ||
prompt = " [y/n]: " | ||
elif default == "yes": | ||
prompt = " [Y/n]: " | ||
elif default == "no": | ||
prompt = " [y/N]: " | ||
else: | ||
raise ValueError("invalid default answer: '%s'" % default) | ||
|
||
while True: | ||
sys.stdout.write(question + prompt) | ||
choice = input().lower() | ||
if default is not None and choice == "": | ||
return valid[default] | ||
elif choice in valid: | ||
return valid[choice] | ||
else: | ||
sys.stdout.write("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n") | ||
|
||
|
||
if __name__ == '__main__': | ||
main(sys.argv) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
click | ||
click-datetime | ||
pre-commit | ||
pyHS100 |