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

3
.gitignore vendored
View file

@ -8,3 +8,6 @@ cbpi.egg-info
logs
venv
cbpi/extension/ui
node_modules
.DS_STORE
.vscode

View file

@ -35,6 +35,12 @@ class CBPiSensor(metaclass=ABCMeta):
def get_unit(self):
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):
self.running = True

View file

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

View file

@ -11,6 +11,7 @@ from tabulate import tabulate
class BasicController:
def __init__(self, cbpi, file):
self.update_key = ""
self.name = self.__class__.__name__
self.cbpi = cbpi
self.cbpi.register(self)
@ -46,7 +47,7 @@ class BasicController:
await self.push_udpate()
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):
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):
if os.path.exists('./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):
super(KettleController, self).__init__(cbpi, "kettle.json")
self.update_key = "kettleupdate"
self.autostart = False
async def on(self, id):

View file

@ -1,5 +1,18 @@
from cbpi.controller.basic_controller import BasicController
import logging
class SensorController(BasicController):
def __init__(self, cbpi):
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 random
import re
import random
from aiohttp import web
from cbpi.api import *
@ -14,6 +14,11 @@ from cbpi.api import *
Property.Actor(label="Param5")])
class CustomSensor(CBPiSensor):
def __init__(self, cbpi, id, props):
super(CustomSensor, self).__init__(cbpi, id, props)
self.value = 0
@action(key="Test", parameters=[])
async def action1(self, **kwargs):
print("ACTION!", kwargs)
@ -30,8 +35,13 @@ class CustomSensor(CBPiSensor):
while self.running is True:
print("HALLO")
self.value = random.randint(0,50)
self.push_update(self.value)
await asyncio.sleep(1)
def get_state(self):
return dict(value=self.value)
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()
await ws.prepare(request)
print(ws)
self._clients.add(ws)
try:
peername = request.transport.get_extra_info('peername')

View file

@ -2,7 +2,7 @@
"data": [
{
"id": "8BLRqagLicCdEBDdc77Sgr",
"name": "Test",
"name": "Heater",
"props": {
"Param3": 2,
"Param4": "",
@ -10,6 +10,20 @@
},
"state": false,
"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",
"name": "Sensor Data",
"props": {
"sensor": 1,
"sensor": "8ohkXvFA9UrkHLsxQL38wu",
"unit": "\u00b0"
},
"type": "Sensor",
@ -92,7 +92,7 @@
"id": "13a6b89d-50c7-4efb-b940-ec174e522314",
"name": "Sensor Data",
"props": {
"sensor": 1,
"sensor": "8ohkXvFA9UrkHLsxQL38wu",
"unit": "\u00b0"
},
"type": "Sensor",
@ -103,7 +103,7 @@
"id": "8d171952-791d-4f72-bfc9-dac8714b839f",
"name": "Sensor Data",
"props": {
"sensor": 1,
"sensor": "8ohkXvFA9UrkHLsxQL38wu",
"unit": "\u00b0"
},
"type": "Sensor",
@ -186,11 +186,11 @@
"id": "3ec3e5d8-f82e-40c1-8c41-cb8286659d3b",
"name": "Led",
"props": {
"actor": 1
"actor": "8BLRqagLicCdEBDdc77Sgr"
},
"type": "Led",
"x": 245,
"y": 220
"x": 240,
"y": 210
},
{
"id": "2e325539-6ed9-4e0d-b1dc-de860c47a1be",
@ -199,18 +199,8 @@
"actor": "8BLRqagLicCdEBDdc77Sgr"
},
"type": "ActorButton",
"x": 210,
"y": 380
},
{
"id": "78b85989-c1bc-47e3-ad7b-0defeabb9bdc",
"name": "Pump",
"props": {
"actor": "8BLRqagLicCdEBDdc77Sgr"
},
"type": "ActorButton",
"x": 305,
"y": 380
"x": 120,
"y": 255
},
{
"id": "3c3f81d0-cdfd-4521-a2fe-2f039f17b583",
@ -245,25 +235,15 @@
"x": 615,
"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",
"name": "Led",
"props": {
"actor": 1
"actor": "Aifjxmw4QdPfU3XbR6iyis"
},
"type": "Led",
"x": 440,
"y": 215
"x": 435,
"y": 210
},
{
"id": "d896b230-8dab-4c33-b73a-1dd74e6de906",
@ -274,10 +254,34 @@
"type": "Led",
"x": 625,
"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": [
{
"condition": [
"8BLRqagLicCdEBDdc77Sgr",
"Aifjxmw4QdPfU3XbR6iyis"
],
"coordinates": [
[
305,
@ -291,6 +295,9 @@
"id": "49e7684e-21a3-4e0b-8e94-60f95abee80f"
},
{
"condition": [
"8BLRqagLicCdEBDdc77Sgr"
],
"coordinates": [
[
400,
@ -304,6 +311,9 @@
"id": "5ba909c1-49a9-46e5-a6d0-1d0350c37aa4"
},
{
"condition": [
"Aifjxmw4QdPfU3XbR6iyis"
],
"coordinates": [
[
255,
@ -329,14 +339,21 @@
"id": "aed2d4d3-b99e-4af5-b8cf-d92d47721be4"
},
{
"condition": [
"HX2bKdobuANehPggYcynnj"
],
"coordinates": [
[
685,
275
],
[
805,
795,
275
],
[
795,
375
]
],
"id": "176fed29-56c2-4534-9cab-8c328d0e138c"

View file

@ -4,7 +4,7 @@
"agitator": "",
"heater": "8BLRqagLicCdEBDdc77Sgr",
"id": "oHxKz3z5RjbsxfSz6KUgov",
"name": "Test",
"name": "Test1111111",
"props": {},
"sensor": "",
"state": {},
@ -40,6 +40,28 @@
"state": {},
"target_temp": null,
"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": [
{
"id": "8ohkXvFA9UrkHLsxQL38wu",
"name": "Test1112222",
"props": {},
"state": {
"value": 0
},
"type": "CustomSensor"
}
]
}

View file

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

View file

@ -10,3 +10,5 @@ aiosqlite>=0.7.0
cryptography>=2.3.1
voluptuous>=0.11.5
pyfiglet>=0.7.6
shortuuid==1.0.1
tabulate==0.8.7