🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
"""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
|