Example #1
0
# -*- coding: utf-8 -*-
import asyncio

from cbpi.api import parameters, Property, CBPiSensor


@parameters([Property.Text(label="Topic", configurable=True)])
class MQTTSensor(CBPiSensor):
    async def on_message(self, message):
        try:
            self.value = float(message)
            self.log_data(self.value)
            self.push_update(self.value)
        except Exception as e:
            print(e)

    def __init__(self, cbpi, id, props):
        super(MQTTSensor, self).__init__(cbpi, id, props)
        self.mqtt_task = self.cbpi.satellite.subcribe(self.props.Topic,
                                                      self.on_message)
        self.value: int = 0

    async def run(self):
        while self.running:
            await asyncio.sleep(1)

    def get_state(self):
        return dict(value=self.value)

    async def on_stop(self):
        if self.mqtt_task.done() is False:
Example #2
0
import asyncio

from cbpi.api import parameters, Property, action
from cbpi.api.step import StepResult, CBPiStep
from cbpi.api.timer import Timer
from datetime import datetime
import time
from voluptuous.schema_builder import message
from cbpi.api.dataclasses import NotificationAction, NotificationType


@parameters([
    Property.Number(label="Timer",
                    description="Time in Minutes",
                    configurable=True),
    Property.Number(label="Temp", configurable=True),
    Property.Sensor(label="Sensor"),
    Property.Kettle(label="Kettle")
])
class MashStep(CBPiStep):
    async def on_timer_done(self, timer):
        self.summary = ""
        await self.next()

    async def on_timer_update(self, timer, seconds):
        self.summary = Timer.format_time(seconds)
        await self.push_update()

    async def on_start(self):
        if self.timer is None:
            self.timer = Timer(int(self.props.Timer) * 60,
Example #3
0
class MQTTActor(CBPiActor):

    # Custom property which can be configured by the user
    @action("Set Power",
            parameters=[
                Property.Number(label="Power",
                                configurable=True,
                                description="Power Setting [0-100]")
            ])
    async def setpower(self, Power=100, **kwargs):
        self.power = int(Power)
        if self.power < 0:
            self.power = 0
        if self.power > 100:
            self.power = 100
        await self.set_power(self.power)

    def __init__(self, cbpi, id, props):
        super(MQTTActor, self).__init__(cbpi, id, props)

    async def on_start(self):
        self.topic = self.props.get("Topic", None)
        self.power = 100
        await self.off()
        self.state = False

    async def on(self, power=None):
        if power is not None:
            if power != self.power:
                power = min(100, power)
                power = max(0, power)
                self.power = round(power)
        await self.cbpi.satellite.publish(
            self.topic, json.dumps({
                "state": "on",
                "power": self.power
            }), True)
        self.state = True
        pass

    async def off(self):
        self.state = False
        await self.cbpi.satellite.publish(
            self.topic, json.dumps({
                "state": "off",
                "power": self.power
            }), True)
        pass

    async def run(self):
        while self.running:
            await asyncio.sleep(1)

    def get_state(self):
        return self.state

    async def set_power(self, power):
        self.power = round(power)
        if self.state == True:
            await self.on(power)
        else:
            await self.off()
        await self.cbpi.actor.actor_update(self.id, power)
        pass
Example #4
0
import time
from voluptuous.schema_builder import message
from cbpi.api.dataclasses import NotificationAction, NotificationType
from cbpi.api.dataclasses import Kettle, Props
from cbpi.api import *
import logging
from socket import timeout
from typing import KeysView
from cbpi.api.config import ConfigType
from cbpi.api.base import CBPiBase
import numpy as np
import warnings



@parameters([Property.Text(label="Notification",configurable = True, description = "Text for notification"),
             Property.Select(label="AutoNext",options=["Yes","No"], description="Automatically move to next step (Yes) or pause after Notification (No)")])
class NotificationStep(CBPiStep):

    async def NextStep(self, **kwargs):
        await self.next()

    async def on_timer_done(self,timer):
        self.summary = self.props.get("Notification","")

        if self.AutoNext == True:
            self.cbpi.notify(self.name, self.props.get("Notification",""), NotificationType.INFO)
            await self.next()
        else:
            self.cbpi.notify(self.name, self.props.get("Notification",""), NotificationType.INFO, action=[NotificationAction("Next Step", self.NextStep)])
            await self.push_update()
Example #5
0
import asyncio
import json
from cbpi.api import parameters, Property, CBPiActor
from cbpi.api import *


@parameters([
    Property.Text(label="Topic", configurable=True, description="MQTT Topic")
])
class MQTTActor(CBPiActor):

    # Custom property which can be configured by the user
    @action("Set Power",
            parameters=[
                Property.Number(label="Power",
                                configurable=True,
                                description="Power Setting [0-100]")
            ])
    async def setpower(self, Power=100, **kwargs):
        self.power = int(Power)
        if self.power < 0:
            self.power = 0
        if self.power > 100:
            self.power = 100
        await self.set_power(self.power)

    def __init__(self, cbpi, id, props):
        super(MQTTActor, self).__init__(cbpi, id, props)

    async def on_start(self):
        self.topic = self.props.get("Topic", None)
Example #6
0
# -*- coding: utf-8 -*-
import asyncio

from cbpi.api import parameters, Property, CBPiSensor
from cbpi.api import *
import logging
import json


@parameters([
    Property.Text(label="Topic", configurable=True, description="MQTT Topic"),
    Property.Text(
        label="PayloadDictionary",
        configurable=True,
        default_value="",
        description="Where to find msg in payload, leave blank for raw payload"
    )
])
class MQTTSensor(CBPiSensor):
    def __init__(self, cbpi, id, props):
        super(MQTTSensor, self).__init__(cbpi, id, props)
        self.Topic = self.props.get("Topic", None)
        self.payload_text = self.props.get("PayloadDictionary", None)
        if self.payload_text != None:
            self.payload_text = self.payload_text.split('.')
        self.mqtt_task = self.cbpi.satellite.subcribe(self.Topic,
                                                      self.on_message)
        self.value: float = 999

    async def on_message(self, message):
        val = json.loads(message)
from cbpi.api import parameters, Property
from . import MQTTActor


@parameters([
    Property.Text(label="Topic", configurable=True, description="MQTT Topic"),
    Property.Text(
        label="Payload",
        configurable=True,
        description=
        "Payload that is sent as MQTT message. Available placeholders are {switch_onoff}: [on|off], {switch_10}: [1|0], {power}: [0-100]."
    )
])
class GenericMqttActor(MQTTActor):
    def __init__(self, cbpi, id, props):
        MQTTActor.__init__(self, cbpi, id, props)
        self.payload = ""

    async def on_start(self):
        await MQTTActor.on_start(self)
        self.payload = self.props.get(
            "Payload", "{{\"state\": \"{switch_onoff}\", \"power\": {power}}}")

    def normalize_power_value(self, power):
        if power is not None:
            if power != self.power:
                power = min(100, power)
                power = max(0, power)
                self.power = round(power)

    async def publish_mqtt_message(self, topic, payload):
Example #8
0
from voluptuous.schema_builder import message
from cbpi.api.dataclasses import NotificationAction, NotificationType
from cbpi.api.dataclasses import Kettle, Props, Fermenter
from cbpi.api import *
import logging
from socket import timeout
from typing import KeysView
from cbpi.api.config import ConfigType
from cbpi.api.base import CBPiBase
import numpy as np
import warnings


@parameters([
    Property.Text(label="Notification",
                  configurable=True,
                  description="Text for notification"),
    Property.Select(
        label="AutoNext",
        options=["Yes", "No"],
        description=
        "Automatically move to next step (Yes) or pause after Notification (No)"
    )
])
class FermenterNotificationStep(CBPiFermentationStep):
    async def NextStep(self, **kwargs):
        await self.next(self.fermenter.id)
        return StepResult.DONE

    async def on_timer_done(self, timer):
        self.summary = self.props.get("Notification", "")
Example #9
0
from voluptuous.schema_builder import message
from cbpi.api.dataclasses import NotificationAction, NotificationType
from cbpi.api.dataclasses import Kettle, Props
from cbpi.api import *
import logging
from socket import timeout
from typing import KeysView
from cbpi.api.config import ConfigType
from cbpi.api.base import CBPiBase
import numpy as np
import warnings


@parameters([
    Property.Text(label="Notification",
                  configurable=True,
                  description="Text for notification"),
    Property.Select(
        label="AutoNext",
        options=["Yes", "No"],
        description=
        "Automatically move to next step (Yes) or pause after Notification (No)"
    )
])
class NotificationStep(CBPiStep):
    async def NextStep(self, **kwargs):
        await self.next()

    async def on_timer_done(self, timer):
        self.summary = self.props.get("Notification", "")