craftbeerpi4-pione/cbpi/controller/actor_controller.py

39 lines
1.3 KiB
Python
Raw Normal View History

2021-02-16 20:37:51 +01:00
from cbpi.api.dataclasses import Actor
from cbpi.controller.basic_controller2 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):
2021-02-16 20:37:51 +01:00
super(ActorController, self).__init__(cbpi, Actor,"actor.json")
2021-01-24 22:14:57 +01:00
self.update_key = "actorupdate"
2021-02-16 20:37:51 +01:00
2021-01-22 23:25:20 +01:00
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)
2021-02-16 20:37:51 +01:00
if item.instance.state is False:
await item.instance.on()
await self.push_udpate()
await self.cbpi.satellite.publish("cbpi/actor/on", "ACTOR 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)
2021-02-16 20:37:51 +01:00
if item.instance.state is True:
await item.instance.off()
await self.push_udpate()
2021-01-22 23:25:20 +01:00
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))
2021-02-16 20:37:51 +01:00