emdbg.power.base
1# Copyright (c) 2023, Auterion AG 2# SPDX-License-Identifier: BSD-3-Clause 3 4import time 5import logging 6LOGGER = logging.getLogger("power") 7 8class Base: 9 """ 10 Interface to enable and disable a single power source. 11 """ 12 def _on(self): 13 raise NotImplementedError 14 15 def _off(self): 16 raise NotImplementedError 17 18 def on(self, delay: float = 1): 19 """Switch relay channel on and wait for `delay` seconds.""" 20 LOGGER.debug(f"On and wait {delay:.1f}s") 21 self._on() 22 time.sleep(delay) 23 24 def off(self, delay: float = 1): 25 """Switch relay channel off and wait for `delay` seconds.""" 26 LOGGER.debug(f"Off and wait {delay:.1f}s") 27 self._off() 28 time.sleep(delay) 29 30 def cycle(self, delay_off: float = 1, delay_on: float = 1): 31 """ 32 Switch relay channel off and wait for `delay_off` seconds, then 33 switch relay channel on and wait for `delay_on` seconds. 34 """ 35 self.off(delay_off) 36 self.on(delay_on)
LOGGER =
<Logger power (WARNING)>
class
Base:
9class Base: 10 """ 11 Interface to enable and disable a single power source. 12 """ 13 def _on(self): 14 raise NotImplementedError 15 16 def _off(self): 17 raise NotImplementedError 18 19 def on(self, delay: float = 1): 20 """Switch relay channel on and wait for `delay` seconds.""" 21 LOGGER.debug(f"On and wait {delay:.1f}s") 22 self._on() 23 time.sleep(delay) 24 25 def off(self, delay: float = 1): 26 """Switch relay channel off and wait for `delay` seconds.""" 27 LOGGER.debug(f"Off and wait {delay:.1f}s") 28 self._off() 29 time.sleep(delay) 30 31 def cycle(self, delay_off: float = 1, delay_on: float = 1): 32 """ 33 Switch relay channel off and wait for `delay_off` seconds, then 34 switch relay channel on and wait for `delay_on` seconds. 35 """ 36 self.off(delay_off) 37 self.on(delay_on)
Interface to enable and disable a single power source.
def
on(self, delay: float = 1):
19 def on(self, delay: float = 1): 20 """Switch relay channel on and wait for `delay` seconds.""" 21 LOGGER.debug(f"On and wait {delay:.1f}s") 22 self._on() 23 time.sleep(delay)
Switch relay channel on and wait for delay
seconds.
def
off(self, delay: float = 1):
25 def off(self, delay: float = 1): 26 """Switch relay channel off and wait for `delay` seconds.""" 27 LOGGER.debug(f"Off and wait {delay:.1f}s") 28 self._off() 29 time.sleep(delay)
Switch relay channel off and wait for delay
seconds.
def
cycle(self, delay_off: float = 1, delay_on: float = 1):
31 def cycle(self, delay_off: float = 1, delay_on: float = 1): 32 """ 33 Switch relay channel off and wait for `delay_off` seconds, then 34 switch relay channel on and wait for `delay_on` seconds. 35 """ 36 self.off(delay_off) 37 self.on(delay_on)
Switch relay channel off and wait for delay_off
seconds, then
switch relay channel on and wait for delay_on
seconds.