Initial commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Base Module Interface
|
||||
Definiert die einheitliche Schnittstelle für alle Gerätemodule
|
||||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List, Dict, Tuple
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BaseModule(ABC):
|
||||
"""
|
||||
Abstrakte Basisklasse für alle Gerätemodule
|
||||
|
||||
Jedes Modul muss nur discover() implementieren und gibt
|
||||
eine Liste von (actors, sensors) zurück.
|
||||
Die Datenbank-Logik bleibt im Hauptscript.
|
||||
"""
|
||||
|
||||
def __init__(self, config):
|
||||
"""
|
||||
Initialisiert das Modul
|
||||
|
||||
Args:
|
||||
config: Config-Objekt mit allen Einstellungen
|
||||
"""
|
||||
self.config = config
|
||||
self.module_name = self.__class__.__name__.replace('Module', '')
|
||||
|
||||
@abstractmethod
|
||||
def discover(self) -> Tuple[List[Dict], List[Dict]]:
|
||||
"""
|
||||
Führt Device Discovery durch
|
||||
|
||||
Returns:
|
||||
Tuple (actors, sensors) mit Listen von Dicts:
|
||||
|
||||
Actor Dict Format:
|
||||
{
|
||||
'type': str, # z.B. 'RollerShutter'
|
||||
'name': str, # z.B. 'Wohnzimmer Rollo'
|
||||
'url': str, # Eindeutige ID/URL
|
||||
'commands': [ # Liste von Commands
|
||||
{
|
||||
'command': str,
|
||||
'parameters': [
|
||||
{
|
||||
'name': str,
|
||||
'type': str,
|
||||
'min': float (optional),
|
||||
'max': float (optional),
|
||||
'values': list (optional)
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'states': [ # Liste von States
|
||||
{
|
||||
'name': str,
|
||||
'type': int/str,
|
||||
'current_value': any,
|
||||
'unit': str (optional)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Sensor Dict Format:
|
||||
{
|
||||
'type': str, # z.B. 'TemperatureSensor'
|
||||
'name': str, # z.B. 'Außentemperatur'
|
||||
'url': str, # Eindeutige ID/URL
|
||||
'states': [ # Liste von States
|
||||
{
|
||||
'name': str,
|
||||
'type': int/str,
|
||||
'current_value': any,
|
||||
'unit': str (optional)
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
pass
|
||||
|
||||
def is_enabled(self) -> bool:
|
||||
"""Prüft ob Modul aktiviert ist"""
|
||||
return True # Override in Subklassen falls nötig
|
||||
|
||||
def get_name(self) -> str:
|
||||
"""Gibt Modulname zurück"""
|
||||
return self.module_name
|
||||
Reference in New Issue
Block a user