Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions ReportState.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_access_token refactored with the following changes:

response = requests.post(url, headers=headers, data=data)

if response.status_code == requests.codes.ok:
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function report_state refactored with the following changes:


return response.status_code == requests.codes.ok

Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

print('Report State has been done successfully.')
else:
print('Report State failed. Please check the log above.')
9 changes: 4 additions & 5 deletions action_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def rsync():
DEVICE = {
"id": k,
}
DEVICE.update(v)
DEVICE |= v
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function rsync refactored with the following changes:


DEVICES.append(DEVICE)
return DEVICES
Expand Down Expand Up @@ -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}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function onQuery refactored with the following changes:

data = rquery(deviceId)
payload['devices'][deviceId] = data
return payload
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function actions refactored with the following changes:

This removes the following comments ( why? ):

# SENDING MQTT MESSAGE

elif i['intent'] == "action.devices.DISCONNECT":
print("\nDISCONNECT ACTION")
else:
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function request_sync refactored with the following changes:

data = {"agentUserId": agent_user_id, "async": True}

response = requests.post(url, json=data)
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 45-45 refactored with the following changes:

This removes the following comments ( why? ):

# for some files to save



@login_manager.user_loader
Expand Down
4 changes: 1 addition & 3 deletions auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function signup_post refactored with the following changes:

This removes the following comments ( why? ):

# get user from database

flash('This Mail is used by another Person')
return redirect(url_for('auth.signup'))
# If not User found Create new
Expand Down
2 changes: 1 addition & 1 deletion generate_service_account_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generate_file refactored with the following changes:

print('Dictionary Generated')

return data
16 changes: 4 additions & 12 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.redirect_uris refactored with the following changes:


@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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Client.default_scopes refactored with the following changes:



class Grant(db.Model):
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Grant.scopes refactored with the following changes:



class Token(db.Model):
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Token.scopes refactored with the following changes:

15 changes: 5 additions & 10 deletions notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_messages refactored with the following changes:

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_publish refactored with the following changes:



@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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_subscribe refactored with the following changes:



@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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_mytopic refactored with the following changes:



@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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function handle_ztopic refactored with the following changes:

2 changes: 1 addition & 1 deletion routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function authorize refactored with the following changes:

if not user:
return redirect('/')
if request.method == 'GET':
Expand Down