Skip to content

Commit

Permalink
Debugged and Tested
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexFluegel committed Dec 16, 2024
1 parent 7d43e14 commit 149ca6f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pyscope/observatory/dlipower_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, name, hostname, userid, password):
try:
self.switch = dlipower.PowerSwitch(hostname=self.hostname, userid=self.userid, password=self.password)
except Exception as e:
logger.error(f"Failed to connect to DLIPowerSwitch: {e}")
logger.error("Failed to connect to DLIPowerSwitch: %s", e)
raise

def CanWrite(self, ID):
Expand All @@ -47,14 +47,14 @@ def SetSwitch(self, ID, State):
try:
outlet.state = 'ON' if State else 'OFF'
except Exception as e:
logger.error(f"Failed to set switch {ID} to {'ON' if State else 'OFF'}: {e}")
logger.error("Failed to set switch %s to %s: %s", ID, 'ON' if State else 'OFF', e)
raise

def SetSwitchName(self, ID, Name):
try:
self.switch[int(ID) - 1].name = Name
except Exception as e:
logger.error(f"Failed to set name for switch {ID}: {e}")
logger.error("Failed to set name for switch %s: %s", ID, e)
raise

def SetSwitchValue(self, ID, Value):
Expand All @@ -68,7 +68,7 @@ def RebootSwitch(self, ID):
try:
outlet.cycle()
except Exception as e:
logger.error(f"Failed to reboot switch {ID}: {e}")
logger.error("Failed to reboot switch %s: %s", ID, e)
raise

def ToggleSwitch(self, ID):
Expand All @@ -80,30 +80,35 @@ def AllOn(self):
for outlet in self.switch:
outlet.state = 'ON'
except Exception as e:
logger.error(f"Failed to turn all switches ON: {e}")
logger.error("Failed to turn all switches ON: %s", e)
raise

def AllOff(self):
try:
for outlet in self.switch:
outlet.state = 'OFF'
except Exception as e:
logger.error(f"Failed to turn all switches OFF: {e}")
logger.error("Failed to turn all switches OFF: %s", e)
raise

def PowerCycleAll(self):
try:
for outlet in self.switch:
outlet.cycle()
if outlet.state == 'ON':
outlet.state = 'OFF'
time.sleep(10)
outlet.state = 'ON'
else:
pass
except Exception as e:
logger.error(f"Failed to power cycle all switches: {e}")
logger.error("Failed to power cycle all switches: %s", e)
raise

def Status(self):
try:
return {outlet.name: outlet.state for outlet in self.switch}
except Exception as e:
logger.error(f"Failed to retrieve status of all switches: {e}")
logger.error("Failed to retrieve status of all switches: %s", e)
raise

@property
Expand Down

0 comments on commit 149ca6f

Please sign in to comment.