more complexity in the test cases

This commit is contained in:
John Lancaster
2024-08-09 17:54:20 -05:00
parent 03ebbcc1f0
commit 24dd2bfd3a
26 changed files with 140 additions and 507 deletions

29
apps/app1/button.py Normal file
View 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}')

View File

@@ -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

3
apps/apps.yaml Normal file
View File

@@ -0,0 +1,3 @@
hello_world:
module: hello
class: HelloWorld

View File

@@ -0,0 +1,13 @@
import arrow
from appdaemon.adapi import ADAPI
class AutomationLib:
"""This is the documentation for AutomationLib"""
def __init__(self, ad: ADAPI) -> None:
self.ad = ad
self.ad.log(f"AutomationLib initialised for app '{self.ad.name}'", level='DEBUG')
def dow(self):
return arrow.now().isoweekday()

View File

@@ -0,0 +1,10 @@
automationlib:
module: automationlib
global: true
my_test_app:
module: test
class: Test
log_level: DEBUG
dependencies:
- automationlib

View File

@@ -0,0 +1 @@
arrow

View File

@@ -0,0 +1,14 @@
from appdaemon.plugins.hass.hassapi import Hass
from automationlib import AutomationLib
class Test(Hass):
"""This is the documentation for Test"""
def initialize(self):
"""."""
self.lib = AutomationLib(self)
self.log('-' * 72)
self.log(f'Day of the week: {self.lib.dow()}')
self.log('-' * 72)

6
apps/button.yaml Normal file
View File

@@ -0,0 +1,6 @@
button_test:
module: app1.button
class: Button
button: Living Room Button
dependencies:
- hello_world

View File

@@ -1,5 +1,5 @@
App1:
module: aadfasdf
module: app1.database
class: Database
other_kwargs: value
dependencies: Sound
@@ -17,3 +17,9 @@ App2:
- App1
- App1Foo
- globals
App3:
module: app2.database
class: OtherDatabaseApp
dependencies:
- App2

0
apps/family/__init__.py Normal file
View File

10
apps/family/child.py Normal file
View File

@@ -0,0 +1,10 @@
from appdaemon.adapi import ADAPI
from .utils import UTILS_VALS
raise ImportError('Fake import error')
class Child(ADAPI):
def initialize(self):
self.log(f'Initialized child with: {UTILS_VALS}')

7
apps/family/family.yaml Normal file
View File

@@ -0,0 +1,7 @@
parent:
module: family.parent
class: Parent
child:
module: family.child
class: Child

8
apps/family/parent.py Normal file
View File

@@ -0,0 +1,8 @@
from appdaemon.adapi import ADAPI
from .utils import UTILS_VALS
class Parent(ADAPI):
def initialize(self):
self.log(f'Initialized parent with: {UTILS_VALS}')

View File

View File

@@ -0,0 +1 @@
OTHER_CITY = 'NYC again'

3
apps/family/utils.py Normal file
View File

@@ -0,0 +1,3 @@
from .relatives.city import OTHER_CITY
UTILS_VALS = 100, 600

View File

@@ -5,4 +5,4 @@ from appdaemon.adapi import ADAPI
class HelloWorld(ADAPI):
def initialize(self):
self.log(f'Initialized app from {Path(__file__).relative_to(self.AD.app_dir.parent)}')
self.log(f'Initialized app from {Path(__file__).relative_to(Path(self.AD.app_dir).parent)}')

View File

@@ -1,3 +1,4 @@
rich
anyio
pydantic
pydantic
# arrow

View File

@@ -4,4 +4,8 @@ test_notifier:
module: variant
class: Variant
log_level: DEBUG
# dependencies: companion_app
# dependencies: companion_app
TestApp:
module: test_notify
class: TestNotifier

View File

@@ -3,7 +3,6 @@ from appdaemon.adapi import ADAPI
class Variant(TestNotifier, ADAPI):
def initialize(self):
self.adapi = self.get_ad_api()
self.log = self.adapi.log
super().initialize()
self.log('Variant of the TestNotifier')
# self.log(' VARIANT '.center(50, '*'))