Compare commits

...

5 Commits

Author SHA1 Message Date
John Lancaster
ce4ede51b1 removed hello stub 2025-06-20 08:21:28 -05:00
John Lancaster
edee038a9f added ruff.toml 2025-06-20 08:21:01 -05:00
John Lancaster
7025bcde99 changed to uv 2025-06-20 08:20:50 -05:00
John Lancaster
ad34a6e919 cleanup 2025-06-20 08:20:26 -05:00
John Lancaster
99936f2c85 cleaned up simple 2025-06-20 08:20:19 -05:00
6 changed files with 39 additions and 107 deletions

8
.gitignore vendored
View File

@@ -4,7 +4,15 @@ __pycache__
.python-version .python-version
.venv .venv
conf/compiled
conf/dashboards
conf/namespaces
conf/www
conf/appdaemon.yaml conf/appdaemon.yaml
conf/secrets.yaml conf/secrets.yaml
log log
*.log
*.db
*.js
*cache*

View File

@@ -1,100 +1,21 @@
from datetime import datetime
from typing import Any
from appdaemon import adbase as ad
from appdaemon import utils from appdaemon import utils
from appdaemon.adbase import ADBase
from appdaemon.plugins.hass import Hass from appdaemon.plugins.hass import Hass
# from globals import GLOBAL_MODE, GLOBAL_VAR
class SimpleApp(Hass): class SimpleApp(Hass):
def initialize(self): def initialize(self) -> None:
match self.ping(): match self.ping():
case float() as ping: case float() as ping:
ping = utils.format_timedelta(ping) ping = utils.format_timedelta(ping)
self.log(f'{self.__class__.__name__} Initialized: {ping}') self.log(f"{self.__class__.__name__} Initialized: {ping}")
case _: case _:
pass pass
# self.get_entity('input_button.test_button').listen_state(self.handle_button)
# self.set_app_pin(True) class BaseApp(ADBase):
def initialize(self) -> None:
# Listen for a button press event with a specific entity_id
self.listen_event(
self.handle_button,
'call_service',
service='press',
entity_id='input_button.test_button'
)
def handle_button(self, event_type: str, data: dict[str, Any], **kwargs: Any) -> None:
match data:
case {"service_data": {"entity_id": eid}}:
friendly_name = self.get_state(eid, attribute='friendly_name')
self.log(f'pressed {friendly_name}')
case _:
self.log(f'Unhandled button press: {data}', level='WARNING')
def delayed(self, **kwargs):
self.log(f'This is a delayed log message: {kwargs}')
# self.reload_apps()
# self.stop_app('child_app')
def my_callback(self, event_type: str, data: dict[str, Any], **kwargs: Any) -> None:
match data:
case {
"service_data": {"entity_id": eid},
"metadata": {"time_fired": time_fired}
}:
friendly_name = self.get_state(eid, attribute='friendly_name')
time_fired = datetime.fromisoformat(time_fired).astimezone(self.AD.tz)
fmt = "%I:%M:%S %p"
self.log(f'{friendly_name} was pressed at {time_fired.strftime(fmt)}')
self.log(f'Kwargs: {kwargs}')
case _:
self.log(f'Unhandled button press: {data}', level='WARNING')
@ad.global_lock
def write(self):
return
# def test_event_handler(self, event_type: str, data: dict[str, Any], **kwargs: Any) -> None:
def test_event_handler(self, *_, value_at_listen, **kwargs: Any) -> None:
# self.log(f' {event_type} '.center(30, '#'))
self.log(f'Data from event: {value_at_listen}')
# self.log(f'Data from registration: {kwargs}')
return
class BaseApp(ad.ADBase):
def initialize(self):
self.adapi = self.get_ad_api() self.adapi = self.get_ad_api()
self.log = self.adapi.log self.log = self.adapi.log
self.hassapi = self.get_plugin_api("HASS") self.hassapi = self.get_plugin_api("HASS")
assert isinstance(self.hassapi, Hass) assert isinstance(self.hassapi, Hass), "HASS API not available"
self.log(f'{self.__class__.__name__} Initialized')
self.config_model = {'name': self.__class__.__name__, 'module': 'simple_app', 'class': 'SimpleApp'}
self.global_vars['abc'] = 123
self.config
self.app_config
# self.log(f'Global mode is set to: {GLOBAL_MODE} ({GLOBAL_MODE.value})')
self.ad = self.AD
# self.adapi.run_in(self.delayed, 0.75)
# self.alexa_notify("Home assistant has been restarted", target="fake")
self.adapi.listen_event(
self.handle_button,
'call_service',
service='press',
entity_id='input_button.test_button'
)
def handle_button(self, event_type: str, data: dict[str, Any], **kwargs: Any) -> None:
self.adapi.fire_event("test_event", values_at_fire=123)

View File

@@ -1,14 +0,0 @@
#
# Main arguments, all optional
#
title: Hello Panel
widget_dimensions: [120, 120]
widget_margins: [5, 5]
columns: 8
label:
widget_type: label
text: Hello World
layout:
- label(2x2)

View File

@@ -8,18 +8,15 @@ authors = [
dependencies = [ dependencies = [
"pytest>=8.3.2", "pytest>=8.3.2",
"gitpython>=3.1.43", "gitpython>=3.1.43",
"appdaemon",
] ]
readme = "README.md" readme = "README.md"
requires-python = ">= 3.8" requires-python = ">= 3.10"
[build-system] [build-system]
requires = ["hatchling"] requires = ["hatchling"]
build-backend = "hatchling.build" build-backend = "hatchling.build"
[tool.rye]
managed = true
dev-dependencies = []
[tool.ruff.format] [tool.ruff.format]
quote-style = "single" quote-style = "single"
@@ -28,3 +25,11 @@ allow-direct-references = true
[tool.hatch.build.targets.wheel] [tool.hatch.build.targets.wheel]
packages = ["src/ad_test"] packages = ["src/ad_test"]
[tool.uv.sources]
appdaemon = {path = "/home/john/Documents/appdaemon" }
[dependency-groups]
dev = [
"ruff>=0.11.13",
]

14
ruff.toml Normal file
View File

@@ -0,0 +1,14 @@
line-length = 88
target-version = "py312"
[lint]
exclude = [
"conf/apps/simple_app/malformed.py"
]
select = ["ALL"]
extend-ignore = ["ANN", "D", "E501", "COM812", "ERA001", "S101", "INP001"]
[format]
quote-style = "single"
indent-style = "space"

View File

@@ -1,2 +0,0 @@
def hello() -> str:
return 'Hello from ad-test!'