mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 16:38:36 +01:00
6dc1c22e20
Error NoneType object as no attribute 'get'
35 lines
802 B
Python
35 lines
802 B
Python
# -*- coding: utf-8 -*-
|
|
import asyncio
|
|
import random
|
|
|
|
from cbpi.api import parameters, CBPiSensor
|
|
|
|
|
|
@parameters([])
|
|
class CustomSensor(CBPiSensor):
|
|
|
|
def __init__(self, cbpi, id, props):
|
|
super(CustomSensor, self).__init__(cbpi, id, props)
|
|
self.value = 0
|
|
|
|
async def run(self):
|
|
while self.running:
|
|
self.value = random.randint(10, 100)
|
|
self.log_data(self.value)
|
|
|
|
self.push_update(self.value)
|
|
await asyncio.sleep(1)
|
|
|
|
def get_state(self):
|
|
return dict(value=self.value)
|
|
|
|
|
|
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:
|
|
'''
|
|
cbpi.plugin.register("CustomSensor", CustomSensor)
|