From c142380bc67cd25b4a7c6b8a446f7f74e27134bc Mon Sep 17 00:00:00 2001 From: Manuel Fritsch Date: Wed, 3 Mar 2021 07:37:54 +0100 Subject: [PATCH] "add seconds to timer at runtime" --- cbpi/__init__.py | 2 +- cbpi/api/timer.py | 12 +++++++----- cbpi/extension/dummysensor/__init__.py | 8 +++++--- cbpi/static/beer_icon.svg | 7 +++++++ cbpi/static/calculator_icon.svg | 10 ++++++++++ cbpi/static/cbpi_icon.svg | 7 +++++++ cbpi/static/control_icon.svg | 7 +++++++ cbpi/static/glass_icon.svg | 7 +++++++ cbpi/static/grain.svg | 7 +++++++ cbpi/static/hops_icon.svg | 7 +++++++ cbpi/static/kettle2_icon.svg | 12 ++++++++++++ cbpi/static/kettle_icon.svg | 7 +++++++ cbpi/static/led.svg | 13 +++++++++++++ cbpi/static/liquid_icon.svg | 7 +++++++ cbpi/static/paddle_icon.svg | 7 +++++++ cbpi/static/pipe_icon.svg | 19 +++++++++++++++++++ cbpi/static/sensor_icon.svg | 15 +++++++++++++++ cbpi/static/svg_icon.svg | 7 +++++++ cbpi/static/tank_icon.svg | 7 +++++++ cbpi/static/target_temp.svg | 7 +++++++ cbpi/static/thermomenter.svg | 13 +++++++++++++ cbpi/static/yeast.svg | 7 +++++++ sample.py | 14 -------------- 23 files changed, 186 insertions(+), 23 deletions(-) create mode 100644 cbpi/static/beer_icon.svg create mode 100644 cbpi/static/calculator_icon.svg create mode 100644 cbpi/static/cbpi_icon.svg create mode 100644 cbpi/static/control_icon.svg create mode 100644 cbpi/static/glass_icon.svg create mode 100644 cbpi/static/grain.svg create mode 100644 cbpi/static/hops_icon.svg create mode 100644 cbpi/static/kettle2_icon.svg create mode 100644 cbpi/static/kettle_icon.svg create mode 100644 cbpi/static/led.svg create mode 100644 cbpi/static/liquid_icon.svg create mode 100644 cbpi/static/paddle_icon.svg create mode 100644 cbpi/static/pipe_icon.svg create mode 100644 cbpi/static/sensor_icon.svg create mode 100644 cbpi/static/svg_icon.svg create mode 100644 cbpi/static/tank_icon.svg create mode 100644 cbpi/static/target_temp.svg create mode 100644 cbpi/static/thermomenter.svg create mode 100644 cbpi/static/yeast.svg diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 2f67a14..1813001 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1 +1 @@ -__version__ = "4.0.0.27" \ No newline at end of file +__version__ = "4.0.0.28" \ No newline at end of file diff --git a/cbpi/api/timer.py b/cbpi/api/timer.py index 0d3bc21..4f20050 100644 --- a/cbpi/api/timer.py +++ b/cbpi/api/timer.py @@ -22,17 +22,19 @@ class Timer(object): self.start_time = time.time() self.count = int(round(self._timemout, 0)) try: - for seconds in range(self.count, 0, -1): + while self.count > 0: + self.count -= 1 if self._update is not None: - await self._update(self,seconds) + await self._update(self,self.count) await asyncio.sleep(1) - except asyncio.CancelledError: end = time.time() duration = end - self.start_time self._timemout = self._timemout - duration - - + + async def add(self, seconds): + self.count = self.count + seconds + def start(self): self._task = asyncio.create_task(self._job()) self._task.add_done_callback(self.done) diff --git a/cbpi/extension/dummysensor/__init__.py b/cbpi/extension/dummysensor/__init__.py index fd24b73..ab2ab08 100644 --- a/cbpi/extension/dummysensor/__init__.py +++ b/cbpi/extension/dummysensor/__init__.py @@ -14,9 +14,11 @@ class CustomSensor(CBPiSensor): super(CustomSensor, self).__init__(cbpi, id, props) self.value = 0 async def run(self): - - while self.running is True: - self.value = random.randint(0,10) + + while True: + self.value = random.randint(10,100) + self.log_data(self.value) + self.push_update(self.value) await asyncio.sleep(1) def get_state(self): diff --git a/cbpi/static/beer_icon.svg b/cbpi/static/beer_icon.svg new file mode 100644 index 0000000..c6d3af0 --- /dev/null +++ b/cbpi/static/beer_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/calculator_icon.svg b/cbpi/static/calculator_icon.svg new file mode 100644 index 0000000..57cfa80 --- /dev/null +++ b/cbpi/static/calculator_icon.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/cbpi/static/cbpi_icon.svg b/cbpi/static/cbpi_icon.svg new file mode 100644 index 0000000..d2371f2 --- /dev/null +++ b/cbpi/static/cbpi_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/control_icon.svg b/cbpi/static/control_icon.svg new file mode 100644 index 0000000..983cc52 --- /dev/null +++ b/cbpi/static/control_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/glass_icon.svg b/cbpi/static/glass_icon.svg new file mode 100644 index 0000000..157f71c --- /dev/null +++ b/cbpi/static/glass_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/grain.svg b/cbpi/static/grain.svg new file mode 100644 index 0000000..29326b9 --- /dev/null +++ b/cbpi/static/grain.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/hops_icon.svg b/cbpi/static/hops_icon.svg new file mode 100644 index 0000000..f9be445 --- /dev/null +++ b/cbpi/static/hops_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/kettle2_icon.svg b/cbpi/static/kettle2_icon.svg new file mode 100644 index 0000000..16737c1 --- /dev/null +++ b/cbpi/static/kettle2_icon.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/cbpi/static/kettle_icon.svg b/cbpi/static/kettle_icon.svg new file mode 100644 index 0000000..d711964 --- /dev/null +++ b/cbpi/static/kettle_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/led.svg b/cbpi/static/led.svg new file mode 100644 index 0000000..c244ced --- /dev/null +++ b/cbpi/static/led.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/cbpi/static/liquid_icon.svg b/cbpi/static/liquid_icon.svg new file mode 100644 index 0000000..08e0fe0 --- /dev/null +++ b/cbpi/static/liquid_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/paddle_icon.svg b/cbpi/static/paddle_icon.svg new file mode 100644 index 0000000..2bdc4d8 --- /dev/null +++ b/cbpi/static/paddle_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/pipe_icon.svg b/cbpi/static/pipe_icon.svg new file mode 100644 index 0000000..513b98b --- /dev/null +++ b/cbpi/static/pipe_icon.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/cbpi/static/sensor_icon.svg b/cbpi/static/sensor_icon.svg new file mode 100644 index 0000000..e0a7c31 --- /dev/null +++ b/cbpi/static/sensor_icon.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/cbpi/static/svg_icon.svg b/cbpi/static/svg_icon.svg new file mode 100644 index 0000000..4da161d --- /dev/null +++ b/cbpi/static/svg_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/tank_icon.svg b/cbpi/static/tank_icon.svg new file mode 100644 index 0000000..9f065d5 --- /dev/null +++ b/cbpi/static/tank_icon.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/target_temp.svg b/cbpi/static/target_temp.svg new file mode 100644 index 0000000..a39d755 --- /dev/null +++ b/cbpi/static/target_temp.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cbpi/static/thermomenter.svg b/cbpi/static/thermomenter.svg new file mode 100644 index 0000000..1485993 --- /dev/null +++ b/cbpi/static/thermomenter.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/cbpi/static/yeast.svg b/cbpi/static/yeast.svg new file mode 100644 index 0000000..76bc1b9 --- /dev/null +++ b/cbpi/static/yeast.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/sample.py b/sample.py index 68c63eb..e69de29 100644 --- a/sample.py +++ b/sample.py @@ -1,14 +0,0 @@ - -import pandas as pd -import datetime - -def dateparse(time_in_secs): - ''' - Internal helper for date parsing - :param time_in_secs: - :return: - ''' - return datetime.datetime.strptime(time_in_secs, '%Y-%m-%d %H:%M:%S') - -df = pd.read_csv("./logs/sensor_JUGteK9KrSVPDxboWjBS4N.log", parse_dates=True, date_parser=dateparse, index_col='DateTime', names=['DateTime',"Values"], header=None) -print({"JUGteK9KrSVPDxboWjBS4N": {"time": df.index.astype(str).tolist(), "value":df.Values.tolist()}})