test with sensor datatype -> should allow datetime in sensors. requires also new ui version (0.3.8)

This commit is contained in:
avollkopf 2023-03-06 20:11:53 +01:00
parent 4c0aa22e98
commit d0278c2448
4 changed files with 14 additions and 5 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.1.5"
__version__ = "4.1.6.b1"
__codename__ = "Groundhog Day"

View file

@ -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)

View file

@ -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

View file

@ -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):