Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot/pip/back/dev/python-dateutil-2.9.0…
Browse files Browse the repository at this point in the history
….post0
  • Loading branch information
kikeelectronico authored Aug 16, 2024
2 parents bd5ac4f + 38d8d2d commit 7c1ed7f
Show file tree
Hide file tree
Showing 56 changed files with 7,657 additions and 11,946 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Homeware is a _Google Home Provider Cloud Service_, a complete ecosystem that allows you to connect any of your DIY home devices to Google Home. Once connected you can control the device from both Google Assistant and Google Home App.

Homeware containts a backend that does the integration and a web forntend that allows you to manage your devices and program tasks.
Homeware containts a backend that does the integration and a web forntend that allows you to manage your devices.

# Install

Expand Down
2 changes: 2 additions & 0 deletions back/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def SetFanSpeed(self):
return "minSpeedReached"
else:
self.saveAndSend('fanSpeedPercent', 'currentFanSpeedPercent')
return ""

def SetFanSpeedRelativeSpeed(self):
# maxSpeedReached
Expand Down Expand Up @@ -413,6 +414,7 @@ def SetModes(self):
state[mode] = self.params['updateModeSettings'][mode]
self.data_conector.updateParamStatus(
self.device, 'currentModeSettings', state)
return ""

def Charge(self):
self.sendCommand("charge")
Expand Down
38 changes: 1 addition & 37 deletions back/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Data:
"""Access to the Homeware database and files."""


version = 'v1.11.0'
version = 'v2.0.0'
homewareFile = 'homeware.json'

def __init__(self):
Expand Down Expand Up @@ -125,15 +125,13 @@ def getGlobal(self):
data = {
'devices': json.loads(self.redis.get('devices')),
'status':self.getStatus(),
'tasks': json.loads(self.redis.get('tasks'))
}
return data

def createFile(self,file):
data = {
'devices': json.loads(self.redis.get('devices')),
'status': self.getStatus(),
'tasks': json.loads(self.redis.get('tasks')),
'secure': {
"domain": self.redis.get("domain").decode('UTF-8'),
"user": self.redis.get("user/username").decode('UTF-8'),
Expand Down Expand Up @@ -176,7 +174,6 @@ def getBackup(self):
data = {
'devices': json.loads(self.redis.get('devices')),
'status': self.getStatus(),
'tasks': json.loads(self.redis.get('tasks')),
'secure': {
"domain": self.redis.get("domain").decode('UTF-8'),
"user": self.redis.get("user/username").decode('UTF-8'),
Expand Down Expand Up @@ -219,7 +216,6 @@ def load(self):
file.close()
# Save the jsons
self.redis.set('devices',json.dumps(data['devices']))
self.redis.set('tasks',json.dumps(data['tasks']))
# Load the status in the database
status = data['status']
devices = status.keys()
Expand Down Expand Up @@ -391,38 +387,6 @@ def updateParamStatus(self, device, param, value):
else:
return False


# TASKS

def getTasks(self):
return json.loads(self.redis.get('tasks'))

def getTask(self, i):
return json.loads(self.redis.get('tasks'))[i]

def updateTask(self, incommingData):
tasks = json.loads(self.redis.get('tasks'))
if int(incommingData['id']) < len(tasks):
tasks[int(incommingData['id'])] = incommingData['task']
self.redis.set('tasks',json.dumps(tasks))
return True
else:
return False

def createTask(self, task):
tasks = json.loads(self.redis.get('tasks'))
tasks.append(task)
self.redis.set('tasks',json.dumps(tasks))

def deleteTask(self, i):
tasks = json.loads(self.redis.get('tasks'))
if i < len(tasks):
del tasks[int(i)]
self.redis.set('tasks', json.dumps(tasks))
return True
else:
return False

# USER

def updatePassword(self, incommingData):
Expand Down
139 changes: 0 additions & 139 deletions back/homewareAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,145 +264,6 @@ def apiStatusGet(value=None):

return response

@app.route("/api/tasks/update", methods=['POST'])
@app.route("/api/tasks/update/", methods=['POST'])
def apiTasksUpdate():

accessLevel = checkAccessLevel(request.headers)

if accessLevel >= 10:
incommingData = request.get_json()
if data_conector.updateTask(incommingData):
response = app.response_class(
response=json.dumps(TWO_O_O),
status=200,
mimetype='application/json'
)
else:
response = app.response_class(
response=json.dumps(FOUR_O_FOUR),
status=404,
mimetype='application/json'
)
else:
data_conector.log(
'Alert', 'Request to API > task > update endpoint with bad authentication')
response = app.response_class(
response=json.dumps(FOUR_O_ONE),
status=401,
mimetype='application/json'
)

return response

@app.route("/api/tasks/create", methods=['POST'])
@app.route("/api/tasks/create/", methods=['POST'])
def apiTasksCreate():

accessLevel = checkAccessLevel(request.headers)

if accessLevel >= 10:
incommingData = request.get_json()
data_conector.createTask(incommingData['task'])
response = app.response_class(
response=json.dumps(TWO_O_O),
status=200,
mimetype='application/json'
)
else:
data_conector.log(
'Alert', 'Request to API > task > create endpoint with bad authentication')
response = app.response_class(
response=json.dumps(FOUR_O_ONE),
status=401,
mimetype='application/json'
)

return response

@app.route("/api/tasks/delete/<value>", methods=['POST'])
@app.route("/api/tasks/delete/<value>/", methods=['POST'])
def apiTasksDelete(value=''):

accessLevel = checkAccessLevel(request.headers)

if accessLevel >= 10:
if data_conector.deleteTask(int(value)):
response = app.response_class(
response=json.dumps(TWO_O_O),
status=200,
mimetype='application/json'
)
else:
response = app.response_class(
response=json.dumps(FOUR_O_FOUR),
status=404,
mimetype='application/json'
)
else:
data_conector.log(
'Alert', 'Request to API > task > delete endpoint with bad authentication')
response = app.response_class(
response=json.dumps(FOUR_O_ONE),
status=401,
mimetype='application/json'
)


return response

@app.route("/api/tasks/get", methods=['GET'])
@app.route("/api/tasks/get/", methods=['GET'])
@app.route("/api/tasks/get/<value>", methods=['GET'])
@app.route("/api/tasks/get/<value>/", methods=['GET'])
def apiTasksGet(value=''):

accessLevel = checkAccessLevel(request.headers)

if accessLevel >= 10:
tasks = data_conector.getTasks()
try:
if not value == '':
if 0 <= int(value) < len(tasks):
response = app.response_class(
response=json.dumps(tasks[int(value)]),
status=200,
mimetype='application/json'
)
else:
response = app.response_class(
response=json.dumps(FOUR_O_FOUR),
status=404,
mimetype='application/json'
)
else:
response = app.response_class(
response=json.dumps(tasks),
status=200,
mimetype='application/json'
)
except:
responseData = {
'error': 'Invalid task ID, it must be a integer',
'code': 400,
'note': 'See the documentation https://homeware.enriquegomez.me/api/'
}
response = app.response_class(
response=json.dumps(responseData),
status=400,
mimetype='application/json'
)
else:
data_conector.log(
'Alert', 'Request to API > task > get endpoint with bad authentication')
response = app.response_class(
response=json.dumps(FOUR_O_ONE),
status=401,
mimetype='application/json'
)

return response

@app.route("/api/global/version", methods=['GET'])
@app.route("/api/global/version/", methods=['GET'])
def apiGlobalVersion():
Expand Down
Loading

0 comments on commit 7c1ed7f

Please sign in to comment.