Initial commit - Phase 3/4
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
60
app/backend/managers/ups_drivers/base.py
Normal file
60
app/backend/managers/ups_drivers/base.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""Base class for UPS drivers."""
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class UPSData:
|
||||
"""Battery data from UPS hardware."""
|
||||
percentage: float # 0-100%
|
||||
voltage: float # mV
|
||||
current: float # A (positive=charging, negative=discharging)
|
||||
is_charging: bool
|
||||
temperature: Optional[float] = None # Celsius
|
||||
time_remaining: Optional[int] = None # Minutes
|
||||
|
||||
|
||||
class UPSDriver(ABC):
|
||||
"""Abstract base class for UPS hardware drivers."""
|
||||
|
||||
@abstractmethod
|
||||
async def initialize(self) -> bool:
|
||||
"""Initialize connection to UPS hardware.
|
||||
|
||||
Returns:
|
||||
True if initialization successful, False otherwise
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def read_data(self) -> UPSData:
|
||||
"""Read current battery data from UPS.
|
||||
|
||||
Returns:
|
||||
UPSData object with current readings
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def is_available(self) -> bool:
|
||||
"""Check if UPS hardware is available.
|
||||
|
||||
Returns:
|
||||
True if hardware is accessible, False otherwise
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def close(self):
|
||||
"""Close connection to UPS hardware."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_model_name(self) -> str:
|
||||
"""Get the UPS model/type name.
|
||||
|
||||
Returns:
|
||||
Human-readable model name
|
||||
"""
|
||||
pass
|
||||
Reference in New Issue
Block a user