-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #66
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ def generate_jwt(service_account): | |
| def get_access_token(signed_jwt): | ||
| url = 'https://accounts.google.com/o/oauth2/token' | ||
| headers = {'Content-Type': 'application/x-www-form-urlencoded'} | ||
| data = 'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=' + signed_jwt | ||
| data = f'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion={signed_jwt}' | ||
| response = requests.post(url, headers=headers, data=data) | ||
|
|
||
| if response.status_code == requests.codes.ok: | ||
|
|
@@ -35,13 +35,10 @@ def get_access_token(signed_jwt): | |
|
|
||
| def report_state(access_token, report_state_file): | ||
| url = 'https://homegraph.googleapis.com/v1/devices:reportStateAndNotification' | ||
| headers = { | ||
| 'X-GFE-SSL': 'yes', | ||
| 'Authorization': 'Bearer ' + access_token | ||
| } | ||
| headers = {'X-GFE-SSL': 'yes', 'Authorization': f'Bearer {access_token}'} | ||
| data = report_state_file | ||
| response = requests.post(url, headers=headers, json=data) | ||
| print('Response: ' + response.text) | ||
| print(f'Response: {response.text}') | ||
|
Comment on lines
-38
to
+41
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| return response.status_code == requests.codes.ok | ||
|
|
||
|
|
@@ -51,9 +48,7 @@ def main(report_state_file): | |
| print('By ReportState') | ||
| signed_jwt = generate_jwt(service_account).decode("utf-8") # Decode | ||
| access_token = get_access_token(signed_jwt) | ||
| success = report_state(access_token, report_state_file) | ||
|
|
||
| if success: | ||
| if success := report_state(access_token, report_state_file): | ||
|
Comment on lines
-54
to
+51
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| print('Report State has been done successfully.') | ||
| else: | ||
| print('Report State failed. Please check the log above.') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ def rsync(): | |
| DEVICE = { | ||
| "id": k, | ||
| } | ||
| DEVICE.update(v) | ||
| DEVICE |= v | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| DEVICES.append(DEVICE) | ||
| return DEVICES | ||
|
|
@@ -74,7 +74,7 @@ def onQuery(body): | |
| for i in body['inputs']: | ||
| for device in i['payload']['devices']: | ||
| deviceId = device['id'] | ||
| print('DEVICE ID: ' + deviceId) | ||
| print(f'DEVICE ID: {deviceId}') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| data = rquery(deviceId) | ||
| payload['devices'][deviceId] = data | ||
| return payload | ||
|
|
@@ -141,8 +141,7 @@ def actions(req): | |
| # SEND TEST MQTT | ||
| deviceId = payload['commands'][0]['ids'][0] | ||
| params = payload['commands'][0]['states'] | ||
| mqtt.publish(topic=str(deviceId) + '/' + 'notification', | ||
| payload=str(params), qos=0) # SENDING MQTT MESSAGE | ||
| mqtt.publish(topic=f'{str(deviceId)}/notification', payload=str(params), qos=0) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| elif i['intent'] == "action.devices.DISCONNECT": | ||
| print("\nDISCONNECT ACTION") | ||
| else: | ||
|
|
@@ -152,7 +151,7 @@ def actions(req): | |
|
|
||
| def request_sync(api_key, agent_user_id): | ||
| """This function does blah blah.""" | ||
| url = 'https://homegraph.googleapis.com/v1/devices:requestSync?key=' + api_key | ||
| url = f'https://homegraph.googleapis.com/v1/devices:requestSync?key={api_key}' | ||
|
Comment on lines
-155
to
+154
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| data = {"agentUserId": agent_user_id, "async": True} | ||
|
|
||
| response = requests.post(url, json=data) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ | |
| FIREBASE_OPTIONS = {'databaseURL': FIREBASE_DATABASEURL} | ||
| initialize_app(FIREBASE_CREDENTIALS, FIREBASE_OPTIONS) | ||
|
|
||
| ALLOWED_EXTENSIONS = set(['txt', 'py']) # for some files to save | ||
| ALLOWED_EXTENSIONS = {'txt', 'py'} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
|
|
||
|
|
||
| @login_manager.user_loader | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,9 +42,7 @@ def signup_post(): | |
| email = request.form.get('email') | ||
| name = request.form.get('name') | ||
| password = request.form.get('password') | ||
| # get user from database | ||
| user = User.query.filter_by(email=email).first() | ||
| if user: | ||
| if user := User.query.filter_by(email=email).first(): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| flash('This Mail is used by another Person') | ||
| return redirect(url_for('auth.signup')) | ||
| # If not User found Create new | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ def generate_file(): | |
| print('Try to replace NewLine Exception') | ||
| data['private_key'] = data['private_key'].replace('\\n', '\n') | ||
| except AttributeError as e: | ||
| print('Error: %s' % e) | ||
| print(f'Error: {e}') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| print('Dictionary Generated') | ||
|
|
||
| return data | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,19 +31,15 @@ def client_type(self): | |
|
|
||
| @property | ||
| def redirect_uris(self): | ||
| if self._redirect_uris: | ||
| return self._redirect_uris.split() | ||
| return [] | ||
| return self._redirect_uris.split() if self._redirect_uris else [] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| @property | ||
| def default_redirect_uri(self): | ||
| return self.redirect_uris[0] | ||
|
|
||
| @property | ||
| def default_scopes(self): | ||
| if self._default_scopes: | ||
| return self._default_scopes.split() | ||
| return [] | ||
| return self._default_scopes.split() if self._default_scopes else [] | ||
|
Comment on lines
-44
to
+42
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class Grant(db.Model): | ||
|
|
@@ -70,9 +66,7 @@ def delete(self): | |
|
|
||
| @property | ||
| def scopes(self): | ||
| if self._scopes: | ||
| return self._scopes.split() | ||
| return [] | ||
| return self._scopes.split() if self._scopes else [] | ||
|
Comment on lines
-73
to
+69
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class Token(db.Model): | ||
|
|
@@ -96,6 +90,4 @@ class Token(db.Model): | |
|
|
||
| @property | ||
| def scopes(self): | ||
| if self._scopes: | ||
| return self._scopes.split() | ||
| return [] | ||
| return self._scopes.split() if self._scopes else [] | ||
|
Comment on lines
-99
to
+93
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,31 +11,26 @@ | |
|
|
||
| @mqtt.on_message() | ||
| def handle_messages(client, userdata, message): | ||
| print('Received message on topic {}: {}' | ||
| .format(message.topic, message.payload.decode())) | ||
| print(f'Received message on topic {message.topic}: {message.payload.decode()}') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if message == 'hi': | ||
| print('== THIS IS NOT JOKE NO HI HERE ==') | ||
|
|
||
|
|
||
| @mqtt.on_publish() | ||
| def handle_publish(client, userdata, mid): | ||
| print('Published message with mid {}.' | ||
| .format(mid)) | ||
| print(f'Published message with mid {mid}.') | ||
|
Comment on lines
-22
to
+21
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @mqtt.on_subscribe() | ||
| def handle_subscribe(client, userdata, mid, granted_qos): | ||
| print('Subscription id {} granted with qos {}.' | ||
| .format(mid, granted_qos)) | ||
| print(f'Subscription id {mid} granted with qos {granted_qos}.') | ||
|
Comment on lines
-28
to
+26
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @mqtt.on_topic('XXX/notification') | ||
| def handle_mytopic(client, userdata, message): | ||
| print('Received message on topic {}: {}' | ||
| .format(message.topic, message.payload.decode())) | ||
| print(f'Received message on topic {message.topic}: {message.payload.decode()}') | ||
|
Comment on lines
-34
to
+31
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @mqtt.on_topic('ZZZ/notification') | ||
| def handle_ztopic(client, userdata, message): | ||
| print('Received message on topic {}: {}' | ||
| .format(message.topic, message.payload.decode())) | ||
| print(f'Received message on topic {message.topic}: {message.payload.decode()}') | ||
|
Comment on lines
-40
to
+36
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,7 @@ def access_token(): | |
| def authorize(*args, **kwargs): | ||
| print("this is authorize") | ||
| user = get_current_user() | ||
| print("Authorize User: %s" % user) | ||
| print(f"Authorize User: {user}") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| if not user: | ||
| return redirect('/') | ||
| if request.method == 'GET': | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
get_access_tokenrefactored with the following changes:use-fstring-for-concatenation)