2019-01-28 22:21:31 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-11-18 15:40:10 +01:00
|
|
|
import asyncio
|
2021-01-22 23:25:20 +01:00
|
|
|
import random
|
|
|
|
import re
|
2021-01-24 22:14:57 +01:00
|
|
|
import random
|
2019-01-14 07:33:59 +01:00
|
|
|
from aiohttp import web
|
2019-01-05 20:43:48 +01:00
|
|
|
from cbpi.api import *
|
2018-11-18 15:40:10 +01:00
|
|
|
|
2021-01-22 23:25:20 +01:00
|
|
|
|
2021-01-30 22:29:33 +01:00
|
|
|
@parameters([])
|
2021-01-23 14:41:26 +01:00
|
|
|
class CustomSensor(CBPiSensor):
|
2021-01-22 23:25:20 +01:00
|
|
|
|
2021-01-24 22:14:57 +01:00
|
|
|
def __init__(self, cbpi, id, props):
|
|
|
|
super(CustomSensor, self).__init__(cbpi, id, props)
|
|
|
|
self.value = 0
|
2021-01-22 23:25:20 +01:00
|
|
|
async def run(self):
|
2021-03-03 07:37:54 +01:00
|
|
|
|
|
|
|
while True:
|
|
|
|
self.value = random.randint(10,100)
|
|
|
|
self.log_data(self.value)
|
|
|
|
|
2021-01-24 22:14:57 +01:00
|
|
|
self.push_update(self.value)
|
2021-02-06 00:40:55 +01:00
|
|
|
await asyncio.sleep(1)
|
2021-01-24 22:14:57 +01:00
|
|
|
def get_state(self):
|
|
|
|
return dict(value=self.value)
|
|
|
|
|
2018-11-18 15:40:10 +01:00
|
|
|
|
|
|
|
def setup(cbpi):
|
|
|
|
|
|
|
|
'''
|
|
|
|
This method is called by the server during startup
|
|
|
|
Here you need to register your plugins at the server
|
|
|
|
|
|
|
|
:param cbpi: the cbpi core
|
|
|
|
:return:
|
|
|
|
'''
|
2021-01-23 14:41:26 +01:00
|
|
|
cbpi.plugin.register("CustomSensor", CustomSensor)
|