add missing dependencies

This commit is contained in:
Manuel Fritsch 2021-01-24 22:14:57 +01:00
parent 6c537bd278
commit 0d2770ef4c
16 changed files with 150 additions and 61 deletions

5
.gitignore vendored
View file

@ -7,4 +7,7 @@ dist
cbpi.egg-info cbpi.egg-info
logs logs
venv venv
cbpi/extension/ui cbpi/extension/ui
node_modules
.DS_STORE
.vscode

View file

@ -35,6 +35,12 @@ class CBPiSensor(metaclass=ABCMeta):
def get_unit(self): def get_unit(self):
pass pass
def push_update(self, value):
try:
self.cbpi.ws.send(dict(topic="sensorstate", id=self.id, value=value))
except:
logging.error("Faild to push sensor update")
async def start(self): async def start(self):
self.running = True self.running = True

View file

@ -4,9 +4,8 @@ from tabulate import tabulate
class ActorController(BasicController): class ActorController(BasicController):
def __init__(self, cbpi): def __init__(self, cbpi):
super(ActorController, self).__init__(cbpi, "actor.json") super(ActorController, self).__init__(cbpi, "actor.json")
self.update_key = "actorupdate"
async def on(self, id): async def on(self, id):
try: try:

View file

@ -11,6 +11,7 @@ from tabulate import tabulate
class BasicController: class BasicController:
def __init__(self, cbpi, file): def __init__(self, cbpi, file):
self.update_key = ""
self.name = self.__class__.__name__ self.name = self.__class__.__name__
self.cbpi = cbpi self.cbpi = cbpi
self.cbpi.register(self) self.cbpi.register(self)
@ -46,7 +47,7 @@ class BasicController:
await self.push_udpate() await self.push_udpate()
async def push_udpate(self): async def push_udpate(self):
await self.cbpi.bus.fire("sensor/update", data=list(map(lambda x: self.create_dict(x), self.data))) self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda x: self.create_dict(x), self.data))))
def create_dict(self, data): def create_dict(self, data):
return dict(name=data.get("name"), id=data.get("id"), type=data.get("type"), status=data.get("status"),props=data.get("props", [])) return dict(name=data.get("name"), id=data.get("id"), type=data.get("type"), status=data.get("status"),props=data.get("props", []))

View file

@ -30,8 +30,3 @@ class DashboardController():
async def delete_content(self, dashboard_id): async def delete_content(self, dashboard_id):
if os.path.exists('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id): if os.path.exists('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id):
os.remove('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id) os.remove('./config/dashboard/cbpi_dashboard_%s.json' % dashboard_id)
async def delete_dashboard(self, dashboard_id):
await DashboardContentModel.delete_by_dashboard_id(dashboard_id)
await self.model.delete(dashboard_id)

View file

@ -5,6 +5,7 @@ class KettleController(BasicController):
def __init__(self, cbpi): def __init__(self, cbpi):
super(KettleController, self).__init__(cbpi, "kettle.json") super(KettleController, self).__init__(cbpi, "kettle.json")
self.update_key = "kettleupdate"
self.autostart = False self.autostart = False
async def on(self, id): async def on(self, id):

View file

@ -1,5 +1,18 @@
from cbpi.controller.basic_controller import BasicController from cbpi.controller.basic_controller import BasicController
import logging
class SensorController(BasicController): class SensorController(BasicController):
def __init__(self, cbpi): def __init__(self, cbpi):
super(SensorController, self).__init__(cbpi, "sensor.json") super(SensorController, self).__init__(cbpi, "sensor.json")
self.update_key = "sensorupdate"
def create_dict(self, data):
try:
instance = data.get("instance")
state = state=instance.get_state()
except Exception as e:
logging.error("Faild to crate actor dict {} ".format(e))
state = dict()
return dict(name=data.get("name"), id=data.get("id"), type=data.get("type"), state=state,props=data.get("props", []))

View file

@ -2,7 +2,7 @@
import asyncio import asyncio
import random import random
import re import re
import random
from aiohttp import web from aiohttp import web
from cbpi.api import * from cbpi.api import *
@ -14,6 +14,11 @@ from cbpi.api import *
Property.Actor(label="Param5")]) Property.Actor(label="Param5")])
class CustomSensor(CBPiSensor): class CustomSensor(CBPiSensor):
def __init__(self, cbpi, id, props):
super(CustomSensor, self).__init__(cbpi, id, props)
self.value = 0
@action(key="Test", parameters=[]) @action(key="Test", parameters=[])
async def action1(self, **kwargs): async def action1(self, **kwargs):
print("ACTION!", kwargs) print("ACTION!", kwargs)
@ -30,8 +35,13 @@ class CustomSensor(CBPiSensor):
while self.running is True: while self.running is True:
print("HALLO") print("HALLO")
self.value = random.randint(0,50)
self.push_update(self.value)
await asyncio.sleep(1) await asyncio.sleep(1)
def get_state(self):
return dict(value=self.value)
def setup(cbpi): def setup(cbpi):

View file

@ -1,13 +0,0 @@
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
app = web.Application()
app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])
if __name__ == '__main__':
web.run_app(app, port="8000")

View file

@ -41,7 +41,6 @@ class CBPiWebSocket:
ws = web.WebSocketResponse() ws = web.WebSocketResponse()
await ws.prepare(request) await ws.prepare(request)
print(ws)
self._clients.add(ws) self._clients.add(ws)
try: try:
peername = request.transport.get_extra_info('peername') peername = request.transport.get_extra_info('peername')

View file

@ -2,7 +2,7 @@
"data": [ "data": [
{ {
"id": "8BLRqagLicCdEBDdc77Sgr", "id": "8BLRqagLicCdEBDdc77Sgr",
"name": "Test", "name": "Heater",
"props": { "props": {
"Param3": 2, "Param3": 2,
"Param4": "", "Param4": "",
@ -10,6 +10,20 @@
}, },
"state": false, "state": false,
"type": "CustomActor" "type": "CustomActor"
},
{
"id": "Aifjxmw4QdPfU3XbR6iyis",
"name": "Pump1",
"props": {},
"state": false,
"type": "CustomActor"
},
{
"id": "HX2bKdobuANehPggYcynnj",
"name": "Pump2",
"props": {},
"state": false,
"type": "CustomActor"
} }
] ]
} }

View file

@ -81,7 +81,7 @@
"id": "4d2c8dfe-61a9-433d-83a8-72f74d17e7e5", "id": "4d2c8dfe-61a9-433d-83a8-72f74d17e7e5",
"name": "Sensor Data", "name": "Sensor Data",
"props": { "props": {
"sensor": 1, "sensor": "8ohkXvFA9UrkHLsxQL38wu",
"unit": "\u00b0" "unit": "\u00b0"
}, },
"type": "Sensor", "type": "Sensor",
@ -92,7 +92,7 @@
"id": "13a6b89d-50c7-4efb-b940-ec174e522314", "id": "13a6b89d-50c7-4efb-b940-ec174e522314",
"name": "Sensor Data", "name": "Sensor Data",
"props": { "props": {
"sensor": 1, "sensor": "8ohkXvFA9UrkHLsxQL38wu",
"unit": "\u00b0" "unit": "\u00b0"
}, },
"type": "Sensor", "type": "Sensor",
@ -103,7 +103,7 @@
"id": "8d171952-791d-4f72-bfc9-dac8714b839f", "id": "8d171952-791d-4f72-bfc9-dac8714b839f",
"name": "Sensor Data", "name": "Sensor Data",
"props": { "props": {
"sensor": 1, "sensor": "8ohkXvFA9UrkHLsxQL38wu",
"unit": "\u00b0" "unit": "\u00b0"
}, },
"type": "Sensor", "type": "Sensor",
@ -186,11 +186,11 @@
"id": "3ec3e5d8-f82e-40c1-8c41-cb8286659d3b", "id": "3ec3e5d8-f82e-40c1-8c41-cb8286659d3b",
"name": "Led", "name": "Led",
"props": { "props": {
"actor": 1 "actor": "8BLRqagLicCdEBDdc77Sgr"
}, },
"type": "Led", "type": "Led",
"x": 245, "x": 240,
"y": 220 "y": 210
}, },
{ {
"id": "2e325539-6ed9-4e0d-b1dc-de860c47a1be", "id": "2e325539-6ed9-4e0d-b1dc-de860c47a1be",
@ -199,18 +199,8 @@
"actor": "8BLRqagLicCdEBDdc77Sgr" "actor": "8BLRqagLicCdEBDdc77Sgr"
}, },
"type": "ActorButton", "type": "ActorButton",
"x": 210, "x": 120,
"y": 380 "y": 255
},
{
"id": "78b85989-c1bc-47e3-ad7b-0defeabb9bdc",
"name": "Pump",
"props": {
"actor": "8BLRqagLicCdEBDdc77Sgr"
},
"type": "ActorButton",
"x": 305,
"y": 380
}, },
{ {
"id": "3c3f81d0-cdfd-4521-a2fe-2f039f17b583", "id": "3c3f81d0-cdfd-4521-a2fe-2f039f17b583",
@ -245,25 +235,15 @@
"x": 615, "x": 615,
"y": 280 "y": 280
}, },
{
"id": "3a9e422f-8d55-4360-8f16-807f9a657988",
"name": "Steps",
"props": {
"width": "400"
},
"type": "Steps",
"x": 20,
"y": 430
},
{ {
"id": "3be00e94-4e06-4a6b-9b8d-c832be73386a", "id": "3be00e94-4e06-4a6b-9b8d-c832be73386a",
"name": "Led", "name": "Led",
"props": { "props": {
"actor": 1 "actor": "Aifjxmw4QdPfU3XbR6iyis"
}, },
"type": "Led", "type": "Led",
"x": 440, "x": 435,
"y": 215 "y": 210
}, },
{ {
"id": "d896b230-8dab-4c33-b73a-1dd74e6de906", "id": "d896b230-8dab-4c33-b73a-1dd74e6de906",
@ -274,10 +254,34 @@
"type": "Led", "type": "Led",
"x": 625, "x": 625,
"y": 215 "y": 215
},
{
"id": "adfe673c-1778-4980-b751-5c613c5c5b76",
"name": "Pump1",
"props": {
"actor": "Aifjxmw4QdPfU3XbR6iyis"
},
"type": "ActorButton",
"x": 360,
"y": 360
},
{
"id": "0e1ea214-9ae0-47c2-902d-cae0947ba8a1",
"name": "Pump2",
"props": {
"actor": "HX2bKdobuANehPggYcynnj"
},
"type": "ActorButton",
"x": 810,
"y": 320
} }
], ],
"pathes": [ "pathes": [
{ {
"condition": [
"8BLRqagLicCdEBDdc77Sgr",
"Aifjxmw4QdPfU3XbR6iyis"
],
"coordinates": [ "coordinates": [
[ [
305, 305,
@ -291,6 +295,9 @@
"id": "49e7684e-21a3-4e0b-8e94-60f95abee80f" "id": "49e7684e-21a3-4e0b-8e94-60f95abee80f"
}, },
{ {
"condition": [
"8BLRqagLicCdEBDdc77Sgr"
],
"coordinates": [ "coordinates": [
[ [
400, 400,
@ -304,6 +311,9 @@
"id": "5ba909c1-49a9-46e5-a6d0-1d0350c37aa4" "id": "5ba909c1-49a9-46e5-a6d0-1d0350c37aa4"
}, },
{ {
"condition": [
"Aifjxmw4QdPfU3XbR6iyis"
],
"coordinates": [ "coordinates": [
[ [
255, 255,
@ -329,14 +339,21 @@
"id": "aed2d4d3-b99e-4af5-b8cf-d92d47721be4" "id": "aed2d4d3-b99e-4af5-b8cf-d92d47721be4"
}, },
{ {
"condition": [
"HX2bKdobuANehPggYcynnj"
],
"coordinates": [ "coordinates": [
[ [
685, 685,
275 275
], ],
[ [
805, 795,
275 275
],
[
795,
375
] ]
], ],
"id": "176fed29-56c2-4534-9cab-8c328d0e138c" "id": "176fed29-56c2-4534-9cab-8c328d0e138c"

View file

@ -4,7 +4,7 @@
"agitator": "", "agitator": "",
"heater": "8BLRqagLicCdEBDdc77Sgr", "heater": "8BLRqagLicCdEBDdc77Sgr",
"id": "oHxKz3z5RjbsxfSz6KUgov", "id": "oHxKz3z5RjbsxfSz6KUgov",
"name": "Test", "name": "Test1111111",
"props": {}, "props": {},
"sensor": "", "sensor": "",
"state": {}, "state": {},
@ -40,6 +40,28 @@
"state": {}, "state": {},
"target_temp": null, "target_temp": null,
"type": "CustomKettleLogic" "type": "CustomKettleLogic"
},
{
"agitator": "",
"heater": "",
"id": "ZfF2N2UnEHtgExNgZJyF5i",
"name": "Test",
"props": {},
"sensor": "",
"state": {},
"target_temp": null,
"type": "CustomKettleLogic"
},
{
"agitator": "",
"heater": "8BLRqagLicCdEBDdc77Sgr",
"id": "oTivUB7LueLeUWoZAnLhwp",
"name": "",
"props": {},
"sensor": "",
"state": {},
"target_temp": null,
"type": ""
} }
] ]
} }

View file

@ -1,5 +1,13 @@
{ {
"data": [ "data": [
{
"id": "8ohkXvFA9UrkHLsxQL38wu",
"name": "Test1112222",
"props": {},
"state": {
"value": 0
},
"type": "CustomSensor"
}
] ]
} }

View file

@ -3,6 +3,18 @@
"name": "WOOHOo" "name": "WOOHOo"
}, },
"profile": [ "profile": [
{
"id": "MSXuATqL56EAeCXrg3XLuY",
"name": "Test",
"props": {
"Param1": 123,
"Param2": "HALLO",
"Param3": 1,
"count": 6,
"wohoo": 0
},
"status": "D",
"type": "CustomStep2"
}
] ]
} }

View file

@ -9,4 +9,6 @@ aiojobs>=0.2.2
aiosqlite>=0.7.0 aiosqlite>=0.7.0
cryptography>=2.3.1 cryptography>=2.3.1
voluptuous>=0.11.5 voluptuous>=0.11.5
pyfiglet>=0.7.6 pyfiglet>=0.7.6
shortuuid==1.0.1
tabulate==0.8.7