2018-11-18 23:09:17 +01:00
|
|
|
import datetime
|
2018-11-01 19:50:04 +01:00
|
|
|
from aiohttp import web
|
|
|
|
from aiojobs.aiohttp import get_scheduler_from_app
|
|
|
|
|
2019-01-05 20:43:48 +01:00
|
|
|
from cbpi.api import *
|
2018-11-01 19:50:04 +01:00
|
|
|
|
2019-01-05 20:43:48 +01:00
|
|
|
from cbpi.utils import json_dumps
|
2019-01-04 09:29:09 +01:00
|
|
|
|
2018-11-01 19:50:04 +01:00
|
|
|
|
|
|
|
class SystemController():
|
|
|
|
|
2018-11-01 21:25:42 +01:00
|
|
|
def __init__(self, cbpi):
|
|
|
|
self.cbpi = cbpi
|
|
|
|
self.service = cbpi.actor
|
|
|
|
self.cbpi.register(self, "/system")
|
2018-11-01 19:50:04 +01:00
|
|
|
|
2019-01-07 22:05:52 +01:00
|
|
|
@request_mapping("/", method="GET", auth_required=False)
|
2019-01-17 22:11:55 +01:00
|
|
|
async def state(self, request):
|
2019-01-21 22:37:00 +01:00
|
|
|
"""
|
|
|
|
---
|
|
|
|
description: Get complete system state
|
|
|
|
tags:
|
|
|
|
- System
|
|
|
|
responses:
|
|
|
|
"200":
|
|
|
|
description: successful operation
|
|
|
|
"""
|
2019-01-04 09:29:09 +01:00
|
|
|
return web.json_response(data=dict(
|
|
|
|
actor=self.cbpi.actor.get_state(),
|
|
|
|
sensor=self.cbpi.sensor.get_state(),
|
|
|
|
kettle=self.cbpi.kettle.get_state(),
|
2019-01-17 22:11:55 +01:00
|
|
|
step=await self.cbpi.step.get_state(),
|
2019-01-07 22:05:52 +01:00
|
|
|
dashboard=self.cbpi.dashboard.get_state(),
|
|
|
|
translations=self.cbpi.translation.get_all(),
|
|
|
|
config=self.cbpi.config.get_state())
|
2019-01-04 09:29:09 +01:00
|
|
|
, dumps=json_dumps)
|
|
|
|
|
2018-11-04 01:55:54 +01:00
|
|
|
@request_mapping("/restart", method="POST", name="RestartServer", auth_required=False)
|
|
|
|
def restart(self, request):
|
2019-01-21 22:37:00 +01:00
|
|
|
"""
|
|
|
|
---
|
|
|
|
description: Restart System - Not implemented
|
|
|
|
tags:
|
|
|
|
- System
|
|
|
|
responses:
|
|
|
|
"200":
|
|
|
|
description: successful operation
|
|
|
|
"""
|
2018-11-04 01:55:54 +01:00
|
|
|
return web.Response(text="NOT IMPLEMENTED")
|
|
|
|
|
|
|
|
@request_mapping("/shutdown", method="POST", name="ShutdownSerer", auth_required=False)
|
|
|
|
def restart(self, request):
|
2019-01-21 22:37:00 +01:00
|
|
|
"""
|
|
|
|
---
|
|
|
|
description: Shutdown System - Not implemented
|
|
|
|
tags:
|
|
|
|
- System
|
|
|
|
responses:
|
|
|
|
"200":
|
|
|
|
description: successful operation
|
|
|
|
"""
|
2018-11-04 01:55:54 +01:00
|
|
|
return web.Response(text="NOT IMPLEMENTED")
|
|
|
|
|
|
|
|
@request_mapping("/jobs", method="GET", name="get_jobs", auth_required=False)
|
2018-11-01 19:50:04 +01:00
|
|
|
def get_all_jobs(self, request):
|
2019-01-21 22:37:00 +01:00
|
|
|
"""
|
|
|
|
---
|
|
|
|
description: Get all running Jobs
|
|
|
|
tags:
|
|
|
|
- System
|
|
|
|
responses:
|
|
|
|
"200":
|
|
|
|
description: successful operation
|
|
|
|
"""
|
2018-11-01 21:25:42 +01:00
|
|
|
scheduler = get_scheduler_from_app(self.cbpi.app)
|
2018-11-18 15:40:10 +01:00
|
|
|
result = []
|
2018-11-01 19:50:04 +01:00
|
|
|
for j in scheduler:
|
2018-11-18 15:40:10 +01:00
|
|
|
try:
|
|
|
|
result.append(dict(name=j.name, type=j.type, time=j.start_time))
|
|
|
|
except:
|
|
|
|
pass
|
2018-11-30 23:27:11 +01:00
|
|
|
return web.json_response(data=result)
|
|
|
|
|
|
|
|
@request_mapping("/events", method="GET", name="get_all_events", auth_required=False)
|
|
|
|
def get_all_events(self, request):
|
2019-01-21 22:37:00 +01:00
|
|
|
"""
|
|
|
|
---
|
|
|
|
description: Get list of all registered events
|
|
|
|
tags:
|
|
|
|
- System
|
|
|
|
responses:
|
|
|
|
"200":
|
|
|
|
description: successful operation
|
|
|
|
"""
|
2019-01-07 22:05:52 +01:00
|
|
|
return web.json_response(data=self.cbpi.bus.dump())
|
|
|
|
|