mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 16:38:36 +01:00
test with sensor datatype -> should allow datetime in sensors. requires also new ui version (0.3.8)
This commit is contained in:
parent
4c0aa22e98
commit
d0278c2448
4 changed files with 14 additions and 5 deletions
|
@ -1,3 +1,3 @@
|
||||||
__version__ = "4.1.5"
|
__version__ = "4.1.6.b1"
|
||||||
__codename__ = "Groundhog Day"
|
__codename__ = "Groundhog Day"
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,10 @@ class Actor:
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return dict(id=self.id, name=self.name, type=self.type, props=self.props.to_dict(), state=self.instance.get_state(), power=self.power)
|
return dict(id=self.id, name=self.name, type=self.type, props=self.props.to_dict(), state=self.instance.get_state(), power=self.power)
|
||||||
|
|
||||||
|
class DataType(Enum):
|
||||||
|
VALUE="value"
|
||||||
|
DATETIME="datetime"
|
||||||
|
STRING="string"
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Sensor:
|
class Sensor:
|
||||||
|
@ -73,6 +77,7 @@ class Sensor:
|
||||||
state: bool = False
|
state: bool = False
|
||||||
type: str = None
|
type: str = None
|
||||||
instance: str = None
|
instance: str = None
|
||||||
|
datatype: DataType = DataType.VALUE
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "name={} props={}, state={}".format(self.name, self.props, self.state)
|
return "name={} props={}, state={}".format(self.name, self.props, self.state)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import asyncio
|
||||||
import logging
|
import logging
|
||||||
from abc import abstractmethod, ABCMeta
|
from abc import abstractmethod, ABCMeta
|
||||||
from cbpi.api.extension import CBPiExtension
|
from cbpi.api.extension import CBPiExtension
|
||||||
|
from cbpi.api.dataclasses import DataType
|
||||||
|
|
||||||
|
|
||||||
from cbpi.api.base import CBPiBase
|
from cbpi.api.base import CBPiBase
|
||||||
|
@ -16,6 +17,7 @@ class CBPiSensor(CBPiBase, metaclass=ABCMeta):
|
||||||
self.data_logger = None
|
self.data_logger = None
|
||||||
self.state = False
|
self.state = False
|
||||||
self.running = False
|
self.running = False
|
||||||
|
self.datatype=DataType.VALUE
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
pass
|
pass
|
||||||
|
@ -33,13 +35,14 @@ class CBPiSensor(CBPiBase, metaclass=ABCMeta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def push_update(self, value, mqtt = True):
|
def push_update(self, value, mqtt = True):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cbpi.ws.send(dict(topic="sensorstate", id=self.id, value=value))
|
self.cbpi.ws.send(dict(topic="sensorstate", id=self.id, value=value, datatype=self.datatype.value))
|
||||||
if mqtt:
|
if mqtt:
|
||||||
self.cbpi.push_update("cbpi/sensordata/{}".format(self.id), dict(id=self.id, value=value), retain=True)
|
self.cbpi.push_update("cbpi/sensordata/{}".format(self.id), dict(id=self.id, value=value, datatype=self.datatype.value), retain=True)
|
||||||
# self.cbpi.push_update("cbpi/sensor/{}/udpate".format(self.id), dict(id=self.id, value=value), retain=True)
|
# self.cbpi.push_update("cbpi/sensor/{}/udpate".format(self.id), dict(id=self.id, value=value), retain=True)
|
||||||
except:
|
except:
|
||||||
logging.error("Failed to push sensor update")
|
logging.error("Failed to push sensor update for sensor {}".format(self.id))
|
||||||
|
|
||||||
async def start(self):
|
async def start(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -4,7 +4,8 @@ import random
|
||||||
import logging
|
import logging
|
||||||
from cbpi.api import *
|
from cbpi.api import *
|
||||||
from cbpi.api.base import CBPiBase
|
from cbpi.api.base import CBPiBase
|
||||||
from cbpi.api.dataclasses import Kettle, Props, Fermenter
|
from cbpi.api.dataclasses import Kettle, Props, Fermenter, DataType
|
||||||
|
import time
|
||||||
|
|
||||||
@parameters([])
|
@parameters([])
|
||||||
class CustomSensor(CBPiSensor):
|
class CustomSensor(CBPiSensor):
|
||||||
|
|
Loading…
Reference in a new issue