mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 22:48:16 +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"
|
||||
|
||||
|
|
|
@ -64,6 +64,10 @@ class Actor:
|
|||
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)
|
||||
|
||||
class DataType(Enum):
|
||||
VALUE="value"
|
||||
DATETIME="datetime"
|
||||
STRING="string"
|
||||
|
||||
@dataclass
|
||||
class Sensor:
|
||||
|
@ -73,6 +77,7 @@ class Sensor:
|
|||
state: bool = False
|
||||
type: str = None
|
||||
instance: str = None
|
||||
datatype: DataType = DataType.VALUE
|
||||
|
||||
def __str__(self):
|
||||
return "name={} props={}, state={}".format(self.name, self.props, self.state)
|
||||
|
|
|
@ -2,6 +2,7 @@ import asyncio
|
|||
import logging
|
||||
from abc import abstractmethod, ABCMeta
|
||||
from cbpi.api.extension import CBPiExtension
|
||||
from cbpi.api.dataclasses import DataType
|
||||
|
||||
|
||||
from cbpi.api.base import CBPiBase
|
||||
|
@ -16,6 +17,7 @@ class CBPiSensor(CBPiBase, metaclass=ABCMeta):
|
|||
self.data_logger = None
|
||||
self.state = False
|
||||
self.running = False
|
||||
self.datatype=DataType.VALUE
|
||||
|
||||
def init(self):
|
||||
pass
|
||||
|
@ -33,13 +35,14 @@ class CBPiSensor(CBPiBase, metaclass=ABCMeta):
|
|||
pass
|
||||
|
||||
def push_update(self, value, mqtt = True):
|
||||
|
||||
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:
|
||||
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)
|
||||
except:
|
||||
logging.error("Failed to push sensor update")
|
||||
logging.error("Failed to push sensor update for sensor {}".format(self.id))
|
||||
|
||||
async def start(self):
|
||||
pass
|
||||
|
|
|
@ -4,7 +4,8 @@ import random
|
|||
import logging
|
||||
from cbpi.api import *
|
||||
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([])
|
||||
class CustomSensor(CBPiSensor):
|
||||
|
|
Loading…
Reference in a new issue