more complexity in the test cases
This commit is contained in:
29
apps/app1/button.py
Normal file
29
apps/app1/button.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import json
|
||||
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
|
||||
class Button(ADAPI):
|
||||
def initialize(self):
|
||||
name = self.args['button']
|
||||
self.handle = self.listen_event(
|
||||
self.handle_button,
|
||||
'MQTT_MESSAGE',
|
||||
topic=f'zigbee2mqtt/{name}',
|
||||
payload=self.payload_filter,
|
||||
)
|
||||
self.log(f"Started MQTT app in namespace '{self._namespace}'")
|
||||
# raise ValueError
|
||||
|
||||
@staticmethod
|
||||
def payload_filter(payload: str):
|
||||
try:
|
||||
return json.loads(payload)['action'] != ''
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def handle_button(self, event_name, data, **kwargs):
|
||||
data['payload'] = json.loads(data['payload'])
|
||||
# if data['payload']['action'] != '':
|
||||
json_str = json.dumps(data, indent=4)
|
||||
self.logger.info(f'{event_name} callback with\n{json_str}\n{kwargs}')
|
||||
@@ -1,6 +1,12 @@
|
||||
from appdaemon.adapi import ADAPI
|
||||
|
||||
|
||||
class Database:
|
||||
class Database(ADAPI):
|
||||
def initialize(self):
|
||||
self.comp = DatabaseComponent(self)
|
||||
self.log('Database with component')
|
||||
|
||||
|
||||
class DatabaseComponent:
|
||||
def __init__(self, ad: ADAPI) -> None:
|
||||
self.ad = ad
|
||||
|
||||
Reference in New Issue
Block a user