Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cbpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "4.7.3"
__version__ = "4.7.4"
__codename__ = "Winter Bock"
9 changes: 6 additions & 3 deletions cbpi/controller/actor_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ async def on(self, id, power=None, output=None):
else:
await self.set_power(id, power)
await self.set_output(id, output)

return True
except Exception as e:
logging.error("Failed to switch on Actor {} {}".format(id, e))
return False

async def off(self, id):
try:
Expand All @@ -65,8 +66,10 @@ async def off(self, id):
self.sorting,
)
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
return True
except Exception as e:
logging.error("Failed to switch on Actor {} {}".format(id, e), True)
return False

async def toogle(self, id):
try:
Expand Down Expand Up @@ -145,14 +148,14 @@ async def timeractor_update(self, id, timer):

async def ws_actor_update(self):
try:
# await self.push_udpate()
self.cbpi.ws.send(
dict(
topic=self.update_key,
data=list(map(lambda x: x.to_dict(), self.data)),
),
self.sorting,
)
# self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
return True
except Exception as e:
logging.error("Failed to update Actors {}".format(e))
return False
5 changes: 3 additions & 2 deletions cbpi/controller/notification_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def notify_log_event(self, record):
)
except Exception as e:
pass
finally:
return True
return True

def get_state(self):
Expand Down Expand Up @@ -162,5 +160,8 @@ def notify_callback(self, notification_id, action_id) -> None:
background_tasks.add(task)
task.add_done_callback(background_tasks.discard)
del self.callback_cache[notification_id]
return True
except Exception as e:
self.logger.error("Failed to call notification callback")
return False

2 changes: 1 addition & 1 deletion cbpi/controller/satellite_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def remove_key(self, d, key):

async def init(self):

self.client = aiomqtt.Client(
self.client = aiomqtt.Client(
self.host,
port=self.port,
username=self.username,
Expand Down
9 changes: 0 additions & 9 deletions cbpi/controller/step_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,6 @@ async def start_step(self, step):
)
logging.error("Failed to start step %s" % step)

async def save_basic(self, data):
logging.info("SAVE Basic Data")
self.basic_data = {
**self.basic_data,
**data,
}
await self.save()
self.push_udpate()

async def call_action(self, id, action, parameter) -> None:
logging.info("Step Controller - call all Action {} {}".format(id, action))
try:
Expand Down
7 changes: 5 additions & 2 deletions cbpi/extension/FermentationStep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,11 @@ async def on_timer_done(self, timer):
return StepResult.DONE

async def on_timer_update(self, timer, seconds):
self.summary = Timer.format_time(seconds)
await self.push_update()
remaining_time = Timer.format_time(seconds)
if remaining_time[0:-3] != self.summary:
logging.info(remaining_time[0:-3])
self.summary = remaining_time[0:-3]
await self.push_update()

async def on_start(self):
self.shutdown = False
Expand Down
72 changes: 37 additions & 35 deletions cbpi/http_endpoints/http_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,32 @@ async def http_get_all(self, request):
"""

---
description: Switch actor on
description: Get all actors
tags:
- Actor
responses:
"204":
"200":
description: successful operation
"""
return web.json_response(data=self.controller.get_state())

@request_mapping(path="/ws_update", auth_required=False)
async def http_get_all(self, request):
async def http_get_ws_update(self, request):
"""

---
description: Update WS actors
description: Update actor state for websocket client
tags:
- Actor
responses:
"204":
"200":
description: successful operation
"500":
description: failed operation
"""
return web.json_response(data=await self.controller.ws_actor_update())

data = await self.controller.ws_actor_update()
return web.json_response(status=200 if data else 500)

@request_mapping(path="/{id:\w+}", auth_required=False)
async def http_get_one(self, request):
"""
Expand All @@ -55,17 +58,16 @@ async def http_get_one(self, request):
in: "path"
description: "Actor ID"
required: true
type: "integer"
format: "int64"
type: "string"
responses:
"200":
description: successful operation
"404":
"500":
description: Actor not found
"""
actor = self.controller.find_by_id(request.match_info["id"])
if actor is None:
return web.json_response(status=404)
return web.json_response(status=500, data={"error": "Actor not found"})

return web.json_response(data=actor.to_dict(), status=200)

Expand Down Expand Up @@ -94,11 +96,11 @@ async def http_add(self, request):
type: object
example:
name: "Actor 1"
type: "CustomActor"
type: "DummyActor"
props: {}

responses:
"204":
"200":
description: successful operation
"""
data = await request.json()
Expand Down Expand Up @@ -166,12 +168,12 @@ async def http_delete_one(self, request):
required: true
type: "string"
responses:
"204":
"200":
description: successful operation
"""
id = request.match_info["id"]
await self.controller.delete(id)
return web.Response(status=204)
return web.Response(status=200)

@request_mapping(path="/{id}/on", method="POST", auth_required=False)
async def http_on(self, request) -> web.Response:
Expand All @@ -190,21 +192,21 @@ async def http_on(self, request) -> web.Response:
type: "string"

responses:
"204":
"200":
description: successful operation
"405":
description: invalid HTTP Met
"500":
description: failed to switch on actor
"""
id = request.match_info["id"]
await self.controller.on(id)
return web.Response(status=204)
status = await self.controller.on(id)
return web.Response(status=200 if status else 500)

@request_mapping(path="/{id}/off", method="POST", auth_required=False)
async def http_off(self, request) -> web.Response:
"""

---
description: Switch actor on
description: Switch actor off
tags:
- Actor

Expand All @@ -216,21 +218,21 @@ async def http_off(self, request) -> web.Response:
type: "string"

responses:
"204":
"200":
description: successful operation
"405":
description: invalid HTTP Met
"500":
description: failed to switch off actor
"""
id = request.match_info["id"]
await self.controller.off(id)
return web.Response(status=204)
status = await self.controller.off(id)
return web.Response(status=200 if status else 500)

@request_mapping(path="/{id}/action", method="POST", auth_required=auth)
async def http_action(self, request) -> web.Response:
"""

---
description: Toogle an actor on or off
description: Call an action of an actor
tags:
- Actor
parameters:
Expand All @@ -242,7 +244,7 @@ async def http_action(self, request) -> web.Response:
format: "int64"
- in: body
name: body
description: Update an actor
description: Call an action of an actor
required: false
schema:
type: object
Expand All @@ -252,7 +254,7 @@ async def http_action(self, request) -> web.Response:
parameter:
type: object
responses:
"204":
"200":
description: successful operation
"""
actor_id = request.match_info["id"]
Expand All @@ -262,7 +264,7 @@ async def http_action(self, request) -> web.Response:
actor_id, data.get("action"), data.get("parameter")
)

return web.Response(status=204)
return web.Response(status=200)

@request_mapping(path="/{id}/set_power", method="POST", auth_required=auth)
async def http_set_power(self, request) -> web.Response:
Expand All @@ -289,13 +291,13 @@ async def http_set_power(self, request) -> web.Response:
temp:
type: integer
responses:
"204":
"200":
description: successful operation
"""
id = request.match_info["id"]
data = await request.json()
await self.controller.set_power(id, data.get("power"))
return web.Response(status=204)
return web.Response(status=200)

@request_mapping(path="/{id}/set_output", method="POST", auth_required=auth)
async def http_set_output(self, request) -> web.Response:
Expand All @@ -319,13 +321,13 @@ async def http_set_output(self, request) -> web.Response:
schema:
type: object
properties:
temp:
output:
type: integer
responses:
"204":
"200":
description: successful operation
"""
id = request.match_info["id"]
data = await request.json()
await self.controller.set_output(id, data.get("output"))
return web.Response(status=204)
return web.Response(status=200)
6 changes: 4 additions & 2 deletions cbpi/http_endpoints/http_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ async def action(self, request):
responses:
"200":
description: successful operation
"400":
description: failed operation
"""

notification_id = request.match_info["id"]
action_id = request.match_info["action_id"]
# print(notification_id, action_id)
self.cbpi.notification.notify_callback(notification_id, action_id)
return web.Response(status=200)
success = self.cbpi.notification.notify_callback(notification_id, action_id)
return web.Response(status=200 if success else 400)

@request_mapping("/delete", method="POST", auth_required=False)
async def restart(self, request):
Expand Down
Loading