craftbeerpi4-pione/cbpi/controller/actor_controller.py

43 lines
1.4 KiB
Python
Raw Normal View History

2021-01-22 23:25:20 +01:00
from cbpi.controller.basic_controller import BasicController
2018-12-29 00:27:19 +01:00
import logging
2021-01-22 23:25:20 +01:00
from tabulate import tabulate
class ActorController(BasicController):
2018-11-01 21:25:42 +01:00
2018-11-01 19:50:04 +01:00
def __init__(self, cbpi):
2018-11-16 20:35:59 +01:00
2021-01-22 23:25:20 +01:00
super(ActorController, self).__init__(cbpi, "actor.json")
async def on(self, id):
2019-01-04 09:29:09 +01:00
try:
2021-01-22 23:25:20 +01:00
item = self.find_by_id(id)
instance = item.get("instance")
await instance.on()
2019-01-04 09:29:09 +01:00
except Exception as e:
2021-01-22 23:25:20 +01:00
logging.error("Faild to switch on Actor {} {}".format(id, e))
2019-01-28 22:21:31 +01:00
2021-01-22 23:25:20 +01:00
async def off(self, id):
try:
item = self.find_by_id(id)
instance = item.get("instance")
await instance.off()
except Exception as e:
logging.error("Faild to switch on Actor {} {}".format(id, e))
2018-12-13 21:45:33 +01:00
2021-01-22 23:25:20 +01:00
async def toogle(self, id):
try:
item = self.find_by_id(id)
instance = item.get("instance")
await instance.toggle()
except Exception as e:
logging.error("Faild to switch on Actor {} {}".format(id, e))
2019-01-28 22:21:31 +01:00
2021-01-22 23:25:20 +01:00
def create_dict(self, data):
try:
instance = data.get("instance")
state = state=instance.get_state()
except Exception as e:
logging.error("Faild to crate actor dict {} ".format(e))
state = dict()
return dict(name=data.get("name"), id=data.get("id"), type=data.get("type"), state=state,props=data.get("props", []))