|
| 1 | +from abc import ABC, abstractmethod |
| 2 | + |
| 3 | + |
| 4 | +class Capability(ABC): |
| 5 | + pass |
| 6 | + |
| 7 | + |
| 8 | +class OutletSwitchingControl(Capability): |
| 9 | + """Switch individual outlets on and off and read their state. |
| 10 | +
|
| 11 | + Outlets are addressed by their physical label (1-based): the first |
| 12 | + switchable outlet is outlet 1. Some strips also carry an always-on outlet |
| 13 | + that is not switchable and is not counted here. |
| 14 | + """ |
| 15 | + |
| 16 | + def turnOutletOn(self, outlet: int): |
| 17 | + self.doSetOutletState(outlet, True) |
| 18 | + |
| 19 | + def turnOutletOff(self, outlet: int): |
| 20 | + self.doSetOutletState(outlet, False) |
| 21 | + |
| 22 | + def setOutletState(self, outlet: int, isOn: bool): |
| 23 | + self.doSetOutletState(outlet, isOn) |
| 24 | + |
| 25 | + def isOutletOn(self, outlet: int) -> bool: |
| 26 | + return self.doGetOutletState(outlet) |
| 27 | + |
| 28 | + @property |
| 29 | + def outletCount(self) -> int: |
| 30 | + return self.doGetOutletCount() |
| 31 | + |
| 32 | + @abstractmethod |
| 33 | + def doSetOutletState(self, outlet: int, isOn: bool): |
| 34 | + ... |
| 35 | + |
| 36 | + @abstractmethod |
| 37 | + def doGetOutletState(self, outlet: int) -> bool: |
| 38 | + ... |
| 39 | + |
| 40 | + @abstractmethod |
| 41 | + def doGetOutletCount(self) -> int: |
| 42 | + ... |
| 43 | + |
| 44 | + |
| 45 | +class DefaultOutletControl(Capability): |
| 46 | + """Set the power-on (boot) state of individual outlets. |
| 47 | +
|
| 48 | + Distinct from OutletSwitchingControl: this configures the state each outlet |
| 49 | + powers up in after the strip loses and regains mains power, not its state |
| 50 | + right now. |
| 51 | + """ |
| 52 | + |
| 53 | + def setOutletDefaultOn(self, outlet: int): |
| 54 | + self.doSetOutletDefaultState(outlet, True) |
| 55 | + |
| 56 | + def setOutletDefaultOff(self, outlet: int): |
| 57 | + self.doSetOutletDefaultState(outlet, False) |
| 58 | + |
| 59 | + def setOutletDefaultState(self, outlet: int, isOn: bool): |
| 60 | + self.doSetOutletDefaultState(outlet, isOn) |
| 61 | + |
| 62 | + @abstractmethod |
| 63 | + def doSetOutletDefaultState(self, outlet: int, isOn: bool): |
| 64 | + ... |
| 65 | + |
| 66 | + |
| 67 | +class CurrentMeteringControl(Capability): |
| 68 | + """Measure the strip's total current draw and accumulated charge. |
| 69 | +
|
| 70 | + Only metering-capable strips (e.g. the PowerUSB "Smart" model) implement |
| 71 | + this; a driver mixes it in only when the hardware supports it. Values are in |
| 72 | + SI units at this boundary: current in amperes, accumulated charge in |
| 73 | + ampere-hours. |
| 74 | + """ |
| 75 | + |
| 76 | + unit = "A" |
| 77 | + isReadable = True |
| 78 | + isWritable = False |
| 79 | + |
| 80 | + def current(self) -> float: |
| 81 | + return self.doGetCurrent() |
| 82 | + |
| 83 | + def accumulatedCharge(self) -> float: |
| 84 | + return self.doGetAccumulatedCharge() |
| 85 | + |
| 86 | + def resetAccumulatedCharge(self): |
| 87 | + self.doResetAccumulatedCharge() |
| 88 | + |
| 89 | + @abstractmethod |
| 90 | + def doGetCurrent(self) -> float: |
| 91 | + ... |
| 92 | + |
| 93 | + @abstractmethod |
| 94 | + def doGetAccumulatedCharge(self) -> float: |
| 95 | + ... |
| 96 | + |
| 97 | + @abstractmethod |
| 98 | + def doResetAccumulatedCharge(self): |
| 99 | + ... |
0 commit comments