From d0278c2448f74007351bd8787ce4e022c7d0c69d Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Mon, 6 Mar 2023 20:11:53 +0100 Subject: [PATCH 01/23] test with sensor datatype -> should allow datetime in sensors. requires also new ui version (0.3.8) --- cbpi/__init__.py | 2 +- cbpi/api/dataclasses.py | 5 +++++ cbpi/api/sensor.py | 9 ++++++--- cbpi/extension/dummysensor/__init__.py | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 17b857f..615854a 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.5" +__version__ = "4.1.6.b1" __codename__ = "Groundhog Day" diff --git a/cbpi/api/dataclasses.py b/cbpi/api/dataclasses.py index 486382a..5007a64 100644 --- a/cbpi/api/dataclasses.py +++ b/cbpi/api/dataclasses.py @@ -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) diff --git a/cbpi/api/sensor.py b/cbpi/api/sensor.py index a539aca..9874ee8 100644 --- a/cbpi/api/sensor.py +++ b/cbpi/api/sensor.py @@ -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 diff --git a/cbpi/extension/dummysensor/__init__.py b/cbpi/extension/dummysensor/__init__.py index c935df2..8e1bbc9 100644 --- a/cbpi/extension/dummysensor/__init__.py +++ b/cbpi/extension/dummysensor/__init__.py @@ -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): From 3b0c12c2e5b91b78892eb81dde3d57763d01452c Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 06:45:33 +0100 Subject: [PATCH 02/23] test workflow --- .github/workflows/build.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3731cc6..e325c9e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,8 +8,14 @@ on: - development pull_request: + +run: | + echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV} env: - image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 + OWNER: '${{ github.repository_owner }}' + +env: + image-name: ghcr.io/${{ OWNER_LC }}/craftbeerpi4 jobs: build: From 5eab4194f092b29a554c4da6ed67e062ebca6f07 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 06:47:11 +0100 Subject: [PATCH 03/23] test workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e325c9e..10c6b1e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: pull_request: -run: | +run: echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV} env: OWNER: '${{ github.repository_owner }}' From 43c60c528d39a840b31f3f60eed4e7a70e49be2e Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 06:52:50 +0100 Subject: [PATCH 04/23] revert back --- .github/workflows/build.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 10c6b1e..effa0ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,9 +8,6 @@ on: - development pull_request: - -run: - echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV} env: OWNER: '${{ github.repository_owner }}' From 29960e15f71dc5f8a6065f841db767263133a06b Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 06:53:11 +0100 Subject: [PATCH 05/23] revert --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index effa0ec..b6e81f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ env: OWNER: '${{ github.repository_owner }}' env: - image-name: ghcr.io/${{ OWNER_LC }}/craftbeerpi4 + image-name: ghcr.io/${{ OWNER }}/craftbeerpi4 jobs: build: From 1a082933b4ac996c6cc5241812ea7d4fce342b93 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 06:54:48 +0100 Subject: [PATCH 06/23] back 1 --- .github/workflows/build.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6e81f2..3731cc6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,10 +9,7 @@ on: pull_request: env: - OWNER: '${{ github.repository_owner }}' - -env: - image-name: ghcr.io/${{ OWNER }}/craftbeerpi4 + image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 jobs: build: From 9834a0dd3c25840c7bc4dda5eb5abe278a22934b Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:00:53 +0100 Subject: [PATCH 07/23] add change string case action --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3731cc6..0a1d599 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,7 @@ name: 'Build CraftBeerPi4' + uses: ASzc/change-string-case-action@v5 + on: push: branches: From 352090e6e72bff56e64a2bec7f671c07eee3ece6 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:03:51 +0100 Subject: [PATCH 08/23] test --- .github/workflows/build.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0a1d599..a021efd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: 'Build CraftBeerPi4' uses: ASzc/change-string-case-action@v5 - + on: push: branches: @@ -10,6 +10,12 @@ on: - development pull_request: +- id: string + with: + string: ${{ github.repository }} +- run: | + echo "${{ steps.string.outputs.lowercase }}" + env: image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 From a0243ff6816e3be9e1a7e346c0351c47283ea748 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:04:45 +0100 Subject: [PATCH 09/23] test --- .github/workflows/build.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a021efd..589fd04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,11 +10,13 @@ on: - development pull_request: -- id: string - with: - string: ${{ github.repository }} -- run: | - echo "${{ steps.string.outputs.lowercase }}" +steps: + - id: string + uses: ASzc/change-string-case-action@v5 + with: + string: ${{ github.repository }} + - run: | + echo "${{ steps.string.outputs.lowercase }}" env: image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 From 80703b3fa3c899f914690516efa6ef79aecc31b0 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:06:04 +0100 Subject: [PATCH 10/23] revert back again --- .github/workflows/build.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 589fd04..6b7c321 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,14 +10,6 @@ on: - development pull_request: -steps: - - id: string - uses: ASzc/change-string-case-action@v5 - with: - string: ${{ github.repository }} - - run: | - echo "${{ steps.string.outputs.lowercase }}" - env: image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 From 531d11ef9574a78834675b8ecbb165638de0b741 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:06:52 +0100 Subject: [PATCH 11/23] original --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6b7c321..3731cc6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,5 @@ name: 'Build CraftBeerPi4' - uses: ASzc/change-string-case-action@v5 - on: push: branches: From 84deba17062828631aa1715a515b1fb0647bf03b Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:08:47 +0100 Subject: [PATCH 12/23] test --- .github/workflows/build.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3731cc6..c64f81e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,14 @@ jobs: runs-on: ubuntu-latest name: Builds the source distribution package steps: + - id: string + uses: ASzc/change-string-case-action@v1 + with: + string: ${{ github.repository_owner }} + - run: | + echo "${{ steps.string.outputs.lowercase }}" + + - name: Checkout source uses: actions/checkout@v2 From 4752c7df958a6af363ceecb2f556f884d21422cd Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:16:53 +0100 Subject: [PATCH 13/23] test2 --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c64f81e..d909c0a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: - id: string uses: ASzc/change-string-case-action@v1 with: - string: ${{ github.repository_owner }} + string: ${{ image-name }} - run: | echo "${{ steps.string.outputs.lowercase }}" @@ -63,7 +63,7 @@ jobs: run: | PUBLISH_IMAGE=false - TAGS="${{ env.image-name }}:dev" + TAGS="${{ env.steps.string.outputs.lowercase }}:dev" # Define the image that will be used as a cached image # to speed up the build process From cb8372fd54ef670d59c6ae5631768c45a2edd106 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:18:09 +0100 Subject: [PATCH 14/23] test --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d909c0a..4455cc9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,7 +63,7 @@ jobs: run: | PUBLISH_IMAGE=false - TAGS="${{ env.steps.string.outputs.lowercase }}:dev" + TAGS="${{ env.image-name }}:dev" # Define the image that will be used as a cached image # to speed up the build process From abf4be74796e3ec9abe969a4e6dda6c6d2ba24ba Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 07:19:30 +0100 Subject: [PATCH 15/23] test --- .github/workflows/build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4455cc9..b33a178 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,13 +16,6 @@ jobs: runs-on: ubuntu-latest name: Builds the source distribution package steps: - - id: string - uses: ASzc/change-string-case-action@v1 - with: - string: ${{ image-name }} - - run: | - echo "${{ steps.string.outputs.lowercase }}" - - name: Checkout source uses: actions/checkout@v2 From 947ee5616b3c79f387be447fc07da13fd73ae037 Mon Sep 17 00:00:00 2001 From: Philipp Grathwohl Date: Tue, 7 Mar 2023 07:50:52 +0100 Subject: [PATCH 16/23] Use lowercase image name when building docker image This avoids issues with github forks that contain uppercase characters. Also updated github actions to avoid other warnings in builds. --- .github/workflows/build.yml | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b33a178..8539fce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: pull_request: env: - image-name: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 + IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/craftbeerpi4 jobs: build: @@ -55,8 +55,11 @@ jobs: id: prep run: | + IMAGE_NAME_LOWERCASE=${IMAGE_NAME,,} + echo "Using image name $IMAGE_NAME_LOWERCASE" + PUBLISH_IMAGE=false - TAGS="${{ env.image-name }}:dev" + TAGS="$IMAGE_NAME_LOWERCASE:dev" # Define the image that will be used as a cached image # to speed up the build process @@ -66,18 +69,21 @@ jobs: # when building master/main use :latest tag and the version number # from the cbpi/__init__.py file VERSION=$(grep -o -E "(([0-9]{1,2}[.]?){2,3}[0-9]+)" cbpi/__init__.py) - LATEST_IMAGE=${{ env.image-name }}:latest + LATEST_IMAGE=$IMAGE_NAME_LOWERCASE:latest BUILD_CACHE_IMAGE_NAME=${LATEST_IMAGE} - TAGS="${LATEST_IMAGE},${{ env.image-name }}:v${VERSION}" - PUBLISH_IMAGE=true + TAGS="${LATEST_IMAGE},$IMAGE_NAME_LOWERCASE:v${VERSION}" + PUBLISH_IMAGE="true" elif [[ $GITHUB_REF_NAME == development ]]; then - PUBLISH_IMAGE=true + PUBLISH_IMAGE="true" fi - # Set output parameters. - echo ::set-output name=tags::${TAGS} - echo ::set-output name=publish_image::${PUBLISH_IMAGE} - echo ::set-output name=build_cache_image_name::${BUILD_CACHE_IMAGE_NAME} + + echo "tags: $TAGS" + echo "publish_image: $PUBLISH_IMAGE" + echo "cache_name: $BUILD_CACHE_IMAGE_NAME" + echo "tags=$TAGS" >> $GITHUB_OUTPUT + echo "publish_image=$PUBLISH_IMAGE" >> $GITHUB_OUTPUT + echo "cache_name=$BUILD_CACHE_IMAGE_NAME" >> $GITHUB_OUTPUT - name: Set up QEMU uses: docker/setup-qemu-action@master @@ -89,23 +95,23 @@ jobs: uses: docker/setup-buildx-action@master - name: Login to GitHub Container Registry - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: builder: ${{ steps.buildx.outputs.name }} context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64 target: deploy - push: ${{ steps.prep.outputs.publish_image }} + push: ${{ steps.prep.outputs.publish_image == 'true' }} tags: ${{ steps.prep.outputs.tags }} - cache-from: type=registry,ref=${{ steps.prep.outputs.build_cache_image_name }} + cache-from: type=registry,ref=${{ steps.prep.outputs.cache_name }} cache-to: type=inline labels: | org.opencontainers.image.title=${{ github.event.repository.name }} From a5b06c826f19b170e2f1a5a9a84775455a249439 Mon Sep 17 00:00:00 2001 From: Alexander Vollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 14:07:01 +0100 Subject: [PATCH 17/23] Update build.yml adding write permission --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8539fce..976fe56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,8 @@ env: jobs: build: runs-on: ubuntu-latest + permissions: + packages: write name: Builds the source distribution package steps: From f7c0c7b2fa05ffa559d8b3294caec5f8ee2b83cb Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:24:23 +0100 Subject: [PATCH 18/23] added Alarmtimer (Sensor with actions) -> Ui 0.3.10 required --- cbpi/__init__.py | 2 +- cbpi/extension/timer/__init__.py | 105 +++++++++++++++++++++++++++++++ cbpi/extension/timer/config.yaml | 3 + 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 cbpi/extension/timer/__init__.py create mode 100644 cbpi/extension/timer/config.yaml diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 615854a..a75a231 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.6.b1" +__version__ = "4.1.6.b2" __codename__ = "Groundhog Day" diff --git a/cbpi/extension/timer/__init__.py b/cbpi/extension/timer/__init__.py new file mode 100644 index 0000000..bd621e8 --- /dev/null +++ b/cbpi/extension/timer/__init__.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +import os +from aiohttp import web +import logging +import asyncio +from cbpi.api import * +from cbpi.api import base +from time import strftime, gmtime +import datetime +from cbpi.api.timer import Timer +from cbpi.api.dataclasses import DataType +from cbpi.api.dataclasses import NotificationAction, NotificationType + +logger = logging.getLogger(__name__) + + +@parameters([]) +class AlarmTimer(CBPiSensor): + + def __init__(self, cbpi, id, props): + super(AlarmTimer, self).__init__(cbpi, id, props) + self.value = "00:00:00" + self.datatype=DataType.STRING + self.timer = None + self.time=0 + self.stopped=False + self.sensor=self.get_sensor(self.id) + + @action(key="Set Timer", parameters=[Property.Number(label="time", description="Time in Minutes", configurable=True)]) + async def set(self, time = 0,**kwargs): + self.stopped=False + self.time = float(time) + self.value=self.calculate_time(self.time) + await self.timer.stop() + self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) + self.timer.start() + await self.timer.stop() + self.timer.is_running = False + logging.info("Set Timer") + + @action(key="Start Timer", parameters=[]) + async def start(self , **kwargs): + if self.timer is None: + self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) + + if self.timer.is_running is not True: + self.cbpi.notify(self.sensor.name,'Timer started', NotificationType.INFO) + self.timer.start() + self.stopped=False + self.timer.is_running = True + else: + self.cbpi.notify(self.sensor.name,'Timer is already running', NotificationType.WARNING) + + @action(key="Stop Timer", parameters=[]) + async def stop(self , **kwargs): + self.stopped=False + await self.timer.stop() + self.timer.is_running = False + self.cbpi.notify(self.sensor.name,'Timer stopped', NotificationType.INFO) + logging.info("Stop Timer") + + @action(key="Reset Timer", parameters=[]) + async def Reset(self , **kwargs): + self.stopped=False + await self.timer.stop() + self.value=self.calculate_time(self.time) + self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) + self.timer.start() + await self.timer.stop() + self.timer.is_running = False + logging.info("Reset Timer") + + async def on_timer_done(self, timer): + #self.value = "Stopped" + if self.stopped is True: + self.cbpi.notify(self.sensor.name,'Timer done', NotificationType.INFO) + + self.timer.is_running = False + pass + + async def on_timer_update(self, timer, seconds): + self.stopped=True + self.value = Timer.format_time(seconds) + #await self.push_update() + + async def NextStep(self): + self.next = True + pass + + async def run(self): + while self.running is True: + self.push_update(self.value) + await asyncio.sleep(1) + pass + + def get_state(self): + return dict(value=self.value) + + def calculate_time(self, time): + return strftime("%H:%M:%S", gmtime(time*60)) + + +def setup(cbpi): + cbpi.plugin.register("AlarmTimer", AlarmTimer) + pass \ No newline at end of file diff --git a/cbpi/extension/timer/config.yaml b/cbpi/extension/timer/config.yaml new file mode 100644 index 0000000..a777645 --- /dev/null +++ b/cbpi/extension/timer/config.yaml @@ -0,0 +1,3 @@ +name: timer +version: 4 +active: true \ No newline at end of file From 4d1c24e2c1fadcaf6d61aa00aad294b3310c300b Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 8 Mar 2023 06:50:18 +0100 Subject: [PATCH 19/23] removed some notifications from alarmtimer --- cbpi/__init__.py | 2 +- cbpi/extension/timer/__init__.py | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index a75a231..395c18a 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.6.b2" +__version__ = "4.1.6.b3" __codename__ = "Groundhog Day" diff --git a/cbpi/extension/timer/__init__.py b/cbpi/extension/timer/__init__.py index bd621e8..2e3cbdf 100644 --- a/cbpi/extension/timer/__init__.py +++ b/cbpi/extension/timer/__init__.py @@ -1,19 +1,15 @@ # -*- coding: utf-8 -*- -import os from aiohttp import web import logging import asyncio from cbpi.api import * from cbpi.api import base from time import strftime, gmtime -import datetime from cbpi.api.timer import Timer from cbpi.api.dataclasses import DataType from cbpi.api.dataclasses import NotificationAction, NotificationType logger = logging.getLogger(__name__) - - @parameters([]) class AlarmTimer(CBPiSensor): @@ -44,7 +40,6 @@ class AlarmTimer(CBPiSensor): self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) if self.timer.is_running is not True: - self.cbpi.notify(self.sensor.name,'Timer started', NotificationType.INFO) self.timer.start() self.stopped=False self.timer.is_running = True @@ -56,7 +51,6 @@ class AlarmTimer(CBPiSensor): self.stopped=False await self.timer.stop() self.timer.is_running = False - self.cbpi.notify(self.sensor.name,'Timer stopped', NotificationType.INFO) logging.info("Stop Timer") @action(key="Reset Timer", parameters=[]) @@ -73,7 +67,7 @@ class AlarmTimer(CBPiSensor): async def on_timer_done(self, timer): #self.value = "Stopped" if self.stopped is True: - self.cbpi.notify(self.sensor.name,'Timer done', NotificationType.INFO) + self.cbpi.notify(self.sensor.name,'Timer done', NotificationType.SUCCESS) self.timer.is_running = False pass @@ -81,11 +75,6 @@ class AlarmTimer(CBPiSensor): async def on_timer_update(self, timer, seconds): self.stopped=True self.value = Timer.format_time(seconds) - #await self.push_update() - - async def NextStep(self): - self.next = True - pass async def run(self): while self.running is True: @@ -99,7 +88,6 @@ class AlarmTimer(CBPiSensor): def calculate_time(self, time): return strftime("%H:%M:%S", gmtime(time*60)) - def setup(cbpi): cbpi.plugin.register("AlarmTimer", AlarmTimer) pass \ No newline at end of file From bffa3c36e37c4fc9373bd992b188ea631ccbf877 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 8 Mar 2023 06:58:17 +0100 Subject: [PATCH 20/23] minor changes to timer code --- cbpi/__init__.py | 2 +- cbpi/extension/timer/__init__.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 395c18a..321c091 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.6.b3" +__version__ = "4.1.6.b4" __codename__ = "Groundhog Day" diff --git a/cbpi/extension/timer/__init__.py b/cbpi/extension/timer/__init__.py index 2e3cbdf..69f66ed 100644 --- a/cbpi/extension/timer/__init__.py +++ b/cbpi/extension/timer/__init__.py @@ -27,10 +27,9 @@ class AlarmTimer(CBPiSensor): self.stopped=False self.time = float(time) self.value=self.calculate_time(self.time) - await self.timer.stop() + if self.timer is None: + await self.timer.stop() self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) - self.timer.start() - await self.timer.stop() self.timer.is_running = False logging.info("Set Timer") @@ -56,11 +55,10 @@ class AlarmTimer(CBPiSensor): @action(key="Reset Timer", parameters=[]) async def Reset(self , **kwargs): self.stopped=False - await self.timer.stop() + if self.timer is None: + await self.timer.stop() self.value=self.calculate_time(self.time) self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) - self.timer.start() - await self.timer.stop() self.timer.is_running = False logging.info("Reset Timer") From f5e6b22f01eb47fdc23de13800a1992a54cc0fd3 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 8 Mar 2023 19:21:07 +0100 Subject: [PATCH 21/23] timer fix --- cbpi/__init__.py | 2 +- cbpi/extension/timer/__init__.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 321c091..82ae046 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.6.b4" +__version__ = "4.1.6.b5" __codename__ = "Groundhog Day" diff --git a/cbpi/extension/timer/__init__.py b/cbpi/extension/timer/__init__.py index 69f66ed..ed16e34 100644 --- a/cbpi/extension/timer/__init__.py +++ b/cbpi/extension/timer/__init__.py @@ -27,9 +27,10 @@ class AlarmTimer(CBPiSensor): self.stopped=False self.time = float(time) self.value=self.calculate_time(self.time) - if self.timer is None: + if self.timer is not None: await self.timer.stop() self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) + await self.timer.stop() self.timer.is_running = False logging.info("Set Timer") @@ -55,10 +56,11 @@ class AlarmTimer(CBPiSensor): @action(key="Reset Timer", parameters=[]) async def Reset(self , **kwargs): self.stopped=False - if self.timer is None: + if self.timer is not None: await self.timer.stop() self.value=self.calculate_time(self.time) self.timer = Timer(int(self.time * 60), on_update=self.on_timer_update, on_done=self.on_timer_done) + await self.timer.stop() self.timer.is_running = False logging.info("Reset Timer") From 2c13b3c62f8c9fe5246f348bfb95b6dd5b834e6d Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 8 Mar 2023 21:39:07 +0100 Subject: [PATCH 22/23] catch nen existing logfile for analytics page --- cbpi/__init__.py | 2 +- cbpi/controller/log_file_controller.py | 13 ++++++++----- cbpi/http_endpoints/http_log.py | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 82ae046..db0e8e4 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.6.b5" +__version__ = "4.1.6.b6" __codename__ = "Groundhog Day" diff --git a/cbpi/controller/log_file_controller.py b/cbpi/controller/log_file_controller.py index 9e8c9a0..1a93fb1 100644 --- a/cbpi/controller/log_file_controller.py +++ b/cbpi/controller/log_file_controller.py @@ -158,11 +158,14 @@ class LogController: dateparse = lambda dates: [datetime.datetime.strptime(d, '%Y-%m-%d %H:%M:%S') for d in dates] result = dict() for id in ids: - all_filenames = glob.glob(os.path.join(self.logsFolderPath,f"sensor_{id}.log*")) - df = pd.concat([pd.read_csv(f, parse_dates=['DateTime'], date_parser=dateparse, index_col='DateTime', names=['DateTime', 'Values'], header=None) for f in all_filenames]) - df = df.resample('60s').max() - df = df.dropna() - result[id] = {"time": df.index.astype(str).tolist(), "value":df.Values.tolist()} + try: + all_filenames = glob.glob(os.path.join(self.logsFolderPath,f"sensor_{id}.log*")) + df = pd.concat([pd.read_csv(f, parse_dates=['DateTime'], date_parser=dateparse, index_col='DateTime', names=['DateTime', 'Values'], header=None) for f in all_filenames]) + df = df.resample('60s').max() + df = df.dropna() + result[id] = {"time": df.index.astype(str).tolist(), "value":df.Values.tolist()} + except: + pass return result diff --git a/cbpi/http_endpoints/http_log.py b/cbpi/http_endpoints/http_log.py index 8183edb..44cac80 100644 --- a/cbpi/http_endpoints/http_log.py +++ b/cbpi/http_endpoints/http_log.py @@ -4,6 +4,7 @@ from cbpi.utils.utils import json_dumps from cbpi.api import request_mapping import os import json +import logging class LogHttpEndpoints: def __init__(self,cbpi): @@ -189,7 +190,8 @@ class LogHttpEndpoints: description: successful operation. """ data = await request.json() - return web.json_response(await self.cbpi.log.get_data2(data), dumps=json_dumps) + values = await self.cbpi.log.get_data2(data) + return web.json_response(values, dumps=json_dumps) @request_mapping(path="/{name}", method="DELETE", auth_required=False) From 8dae24502b6facd20990931941c9e0e5a76abd7c Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 9 Mar 2023 07:28:26 +0100 Subject: [PATCH 23/23] bump revision --- cbpi/__init__.py | 2 +- tests/cbpi-test-config/config.json | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index db0e8e4..3e9f879 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.6.b6" +__version__ = "4.1.6" __codename__ = "Groundhog Day" diff --git a/tests/cbpi-test-config/config.json b/tests/cbpi-test-config/config.json index d6ab711..8fef776 100644 --- a/tests/cbpi-test-config/config.json +++ b/tests/cbpi-test-config/config.json @@ -45,6 +45,22 @@ "type": "string", "value": "Some New Brewery Name" }, + "BoilAutoTimer": { + "description": "Start Boil timer automatically if Temp does not change for 5 Minutes and is above 95C/203F", + "name": "BoilAutoTimer", + "options": [ + { + "label": "Yes", + "value": "Yes" + }, + { + "label": "No", + "value": "No" + } + ], + "type": "select", + "value": "No" + }, "BoilKettle": { "description": "Define Kettle that is used for Boil, Whirlpool and Cooldown. If not selected, MASH_TUN will be used", "name": "BoilKettle", @@ -107,6 +123,13 @@ "type": "select", "value": "No" }, + "INFLUXDBMEASUREMENT": { + "description": "Name of the measurement in your INFLUXDB database (default: measurement)", + "name": "INFLUXDBMEASUREMENT", + "options": null, + "type": "string", + "value": "measurement" + }, "INFLUXDBNAME": { "description": "Name of your influxdb database name (If INFLUXDBCLOUD set to Yes use bucket of your influxdb cloud database)", "name": "INFLUXDBNAME",