2021-02-10 22:11:35 +01:00
|
|
|
from cbpi.api.base import CBPiBase
|
2019-01-05 20:43:48 +01:00
|
|
|
from cbpi.api.extension import CBPiExtension
|
2021-01-22 23:25:20 +01:00
|
|
|
from abc import ABCMeta
|
|
|
|
import logging
|
|
|
|
import asyncio
|
2019-01-05 20:43:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-02-10 22:11:35 +01:00
|
|
|
class CBPiKettleLogic(CBPiBase, metaclass=ABCMeta):
|
2021-01-22 23:25:20 +01:00
|
|
|
|
|
|
|
def __init__(self, cbpi, id, props):
|
|
|
|
self.cbpi = cbpi
|
|
|
|
self.id = id
|
|
|
|
self.props = props
|
|
|
|
self.state = False
|
|
|
|
self.running = False
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def run(self):
|
2021-01-30 22:29:33 +01:00
|
|
|
self.state = True
|
2021-01-22 23:25:20 +01:00
|
|
|
while self.running:
|
|
|
|
await asyncio.sleep(1)
|
2021-01-30 22:29:33 +01:00
|
|
|
self.state = False
|
2021-01-22 23:25:20 +01:00
|
|
|
|
|
|
|
def get_state(self):
|
2021-01-30 22:29:33 +01:00
|
|
|
return dict(running=self.running)
|
2021-01-22 23:25:20 +01:00
|
|
|
|
|
|
|
async def start(self):
|
|
|
|
self.running = True
|
|
|
|
|
|
|
|
async def stop(self):
|
2021-02-10 22:11:35 +01:00
|
|
|
self.task.cancel()
|
|
|
|
await self.task
|