From 86a23559987988585960f61a80e5c3a48c28a69d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 29 Nov 2022 09:22:01 +1100 Subject: [PATCH 1/4] added getall command --- pcomfortcloud/__main__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pcomfortcloud/__main__.py b/pcomfortcloud/__main__.py index b2a19a6..378f66b 100644 --- a/pcomfortcloud/__main__.py +++ b/pcomfortcloud/__main__.py @@ -68,6 +68,10 @@ def main(): 'list', help="Get a list of all devices") + get_parser = commandparser.add_parser( + 'getall', + help="Get status of all devices") + get_parser = commandparser.add_parser( 'get', help="Get status of a device") @@ -210,6 +214,17 @@ def main(): print("device #{}".format(idx + 1)) print_result(device, 4) + if args.command == 'getall': + print("status of all devices") + for idx, device in enumerate(session.get_devices()): + if(idx > 0): + print('') + + print("device #{}".format(idx + 1)) + device = session.get_devices()[idx - 1] + print("reading from device '{}' ({})".format(device['name'], device['id'])) + print_result( session.get_device(device['id']) ) + if args.command == 'get': if int(args.device) <= 0 or int(args.device) > len(session.get_devices()): raise Exception("device not found, acceptable device id is from {} to {}".format(1, len(session.get_devices()))) From 472e02e00228cb44b5850d53bb8879fe07edd417 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 29 Nov 2022 10:26:32 +1100 Subject: [PATCH 2/4] updated readme with getall --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d5e1ba4..902f9cd 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,16 @@ A python module for reading and changing status of panasonic climate devices thr ## Command line usage ``` -usage: pcomfortcloud.py [-h] [-t TOKEN] username password {list,get,set} ... +usage: pcomfortcloud.py [-h] [-t TOKEN] username password {list,getall,get,set} ... Read or change status of Panasonic Climate devices positional arguments: username Username for Panasonic Comfort Cloud password Password for Panasonic Comfort Cloud - {list,get,set,dump} commands + {list,getall,get,set,dump} commands list Get a list of all devices + getall Get status of all devices get Get status of a device set Set status of a device dump Dump raw data of a device From 6676546023326a58d4d4f9140292ff2fb9c94717 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 8 Feb 2023 08:12:46 +1100 Subject: [PATCH 3/4] added auth file and documentation for it --- README.md | 12 ++++++++++++ pcomfortcloud/__main__.py | 27 +++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 902f9cd..face139 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ optional arguments: -h, --help show this help message and exit -t TOKEN, --token TOKEN File to store token in + -a AUTHFILE, --authfile AUTHFILE + File to store credentials in (instead of using username and password) -s [BOOL], --skipVerify [BOOL] Skip Ssl verification -r [BOOL], --raw [BOOL] @@ -120,3 +122,13 @@ can be found at https://pypi.org/project/pcomfortcloud/ ### How to publish package; - `python .\setup.py sdist bdist_wheel` - `python -m twine upload dist/*` + +## Auth File +Instead of specifying the username and password on the command line, they can optionally, be stored in a YAML file. +To use the auth file, on the command line, set the username to authfile and set the password to the full path of the YAML file + +The format of the auth file is: +``` +username: USERNAME +password: PASSWORD +``` \ No newline at end of file diff --git a/pcomfortcloud/__main__.py b/pcomfortcloud/__main__.py index 378f66b..267f4fb 100644 --- a/pcomfortcloud/__main__.py +++ b/pcomfortcloud/__main__.py @@ -1,5 +1,6 @@ import argparse import json +import yaml import pcomfortcloud from enum import Enum @@ -37,11 +38,11 @@ def main(): parser.add_argument( 'username', - help='Username for pcomfortcloud Comfort Cloud') + help='Username for pcomfortcloud Comfort Cloud. If "authfile" is used then the password parameter is a YAML file containing both the username and password') parser.add_argument( 'password', - help='Password for pcomfortcloud Comfort Cloud') + help='Password for pcomfortcloud Comfort Cloud. If "authfile" used as the username, then this parameter is a YAML file containing both the username and password') parser.add_argument( '-t', '--token', @@ -201,6 +202,27 @@ def main(): help='date of day like 20190807') args = parser.parse_args() + + # if username has been specified as the string "auth" then password is actually a filename containing both the username and password + if args.username == "authfile": + # args.password should actually be a filename, try and read it as as yaml file + with open(args.password, "r") as file: + try: + cfg = yaml.load(file, Loader=yaml.FullLoader) + # grab the user and pass out of the auth file + # replacing that which was specified on the command line + args.username=cfg["username"] + args.password=cfg["password"] + print ("Retrieved username and password from authfile") + except yaml.YAMLError as e: + print("YAML format error with authfile: " + args.authfile) + print(e) + quit() + except Exception as e: + print("YAML configuration error with authfile (missing fields?): " + args.authfile) + print(e) + quit() + session = pcomfortcloud.Session(args.username, args.password, args.token, args.raw, args.skipVerify == False) session.login() @@ -230,6 +252,7 @@ def main(): raise Exception("device not found, acceptable device id is from {} to {}".format(1, len(session.get_devices()))) device = session.get_devices()[int(args.device) - 1] + print("reading from device '{}' ({})".format(device['name'], device['id'])) print_result( session.get_device(device['id']) ) From a1765b79abe55e01acd729c35a8f21b829b3aa8a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 29 Mar 2023 09:54:23 +1100 Subject: [PATCH 4/4] changed authfile in username parameter to # instead --- pcomfortcloud/__main__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pcomfortcloud/__main__.py b/pcomfortcloud/__main__.py index 267f4fb..a1d3b1a 100644 --- a/pcomfortcloud/__main__.py +++ b/pcomfortcloud/__main__.py @@ -38,11 +38,11 @@ def main(): parser.add_argument( 'username', - help='Username for pcomfortcloud Comfort Cloud. If "authfile" is used then the password parameter is a YAML file containing both the username and password') + help='Username for pcomfortcloud Comfort Cloud. If "#" is used then the password parameter is a YAML file containing both the username and password') parser.add_argument( 'password', - help='Password for pcomfortcloud Comfort Cloud. If "authfile" used as the username, then this parameter is a YAML file containing both the username and password') + help='Password for pcomfortcloud Comfort Cloud. If "#" used as the username, then this parameter is a YAML file containing both the username and password') parser.add_argument( '-t', '--token', @@ -204,7 +204,7 @@ def main(): args = parser.parse_args() # if username has been specified as the string "auth" then password is actually a filename containing both the username and password - if args.username == "authfile": + if args.username == "#": # args.password should actually be a filename, try and read it as as yaml file with open(args.password, "r") as file: try: