"""Hello World example plugin for Dangerous Pi.""" import sys from pathlib import Path # Add app directory to path for imports app_path = Path(__file__).parent.parent.parent if str(app_path) not in sys.path: sys.path.insert(0, str(app_path)) from backend.managers.plugin_manager import PluginBase, PluginMetadata class HelloWorldPlugin(PluginBase): """Example plugin that demonstrates the plugin framework.""" def __init__(self): """Initialize the Hello World plugin.""" super().__init__() self.counter = 0 async def on_load(self): """Called when the plugin is loaded.""" print("Hello World Plugin: Loaded!") async def on_enable(self): """Called when the plugin is enabled.""" print("Hello World Plugin: Enabled!") # Register a hook for PM3 commands async def pm3_command_hook(command: str): """Hook that logs PM3 commands.""" self.counter += 1 print(f"Hello World Plugin: PM3 command #{self.counter}: {command}") return {"plugin": "hello_world", "command_count": self.counter} self.register_hook("pm3_command", pm3_command_hook) # Register a hook for update checks async def update_check_hook(): """Hook that runs on update checks.""" print("Hello World Plugin: Update check performed") return {"plugin": "hello_world", "message": "Hello from plugin!"} self.register_hook("update_check", update_check_hook) async def on_disable(self): """Called when the plugin is disabled.""" print(f"Hello World Plugin: Disabled! (processed {self.counter} commands)") async def on_unload(self): """Called when the plugin is unloaded.""" print("Hello World Plugin: Unloaded! Goodbye!") def get_metadata(self) -> PluginMetadata: """Get plugin metadata.""" return self.metadata