forked from hvanderlaan/ikea-smartlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hvanderlaan#44 from maltejur/master
add tradfri_authenticate.py and update README.md
- Loading branch information
Showing
3 changed files
with
131 additions
and
37 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
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,60 @@ | ||
#!/usr/bin/env python | ||
|
||
# file : tradfri-authenticate.py | ||
# purpose : authenticate api user and generate configuration file | ||
# | ||
# author : maltejur | ||
# date : 2020/10/24 | ||
|
||
""" | ||
tradfri-authenticate.py - authenticate api user and generate configuration file | ||
This module requires libcoap with dTLS compiled, at this moment there is no python coap module | ||
that supports coap with dTLS. see ../bin/README how to compile libcoap with dTLS support | ||
""" | ||
|
||
# pylint convention disablement: | ||
# C0103 -> invalid-name | ||
# C0200 -> consider-using-enumerate | ||
# pylint: disable=C0200, C0103 | ||
|
||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import sys | ||
import time | ||
import ConfigParser | ||
|
||
from tradfri import tradfriActions | ||
|
||
def main(): | ||
""" main function """ | ||
conf = ConfigParser.ConfigParser() | ||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
conf.read(script_dir + '/tradfri.cfg') | ||
|
||
hubip = raw_input("\nhub ip:\t\t") | ||
securityCode = raw_input("security code: \t") | ||
|
||
print("\n[ ] acquiring api key ...", end="") | ||
|
||
apiuser, apikey = tradfriActions.tradfri_authenticate(hubip, securityCode) | ||
|
||
print("\r[+]\n\nuser:\t{}\napikey:\t{}\n".format(apiuser, apikey)) | ||
|
||
print("[ ] writing configuration file ...", end="") | ||
|
||
conf.add_section('tradfri') | ||
conf.set("tradfri", "hubip", hubip) | ||
conf.set("tradfri", "apiuser", apiuser) | ||
conf.set("tradfri", "apikey", apikey) | ||
conf.write(open(script_dir + '/tradfri.cfg','w')) | ||
|
||
print("\r[+]\n") | ||
|
||
print("all done!\n") | ||
|
||
if __name__ == "__main__": | ||
main() | ||
sys.exit(0) |
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