0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-01-30 11:36:20 +00:00
alerta_alerta/alerta/api/v2/switch.py
2013-04-04 13:21:20 +01:00

47 lines
No EOL
1 KiB
Python

class SwitchState(object):
ON = True
OFF = False
@staticmethod
def to_state(string):
return SwitchState.ON if string == "ON" else SwitchState.OFF
@staticmethod
def to_string(state):
return "ON" if state else "OFF"
class Switch(object):
switches = []
def __init__(self, name, description=None, state=SwitchState.ON):
self.name = name
self.description = description
self.state = state
Switch.switches.append(self)
def __repr__(self):
return 'Switch(name=%s, description=%s, state=%s)' % (self.name, self.description,
SwitchState.to_string(self.state))
@classmethod
def get(cls, name):
for s in Switch.switches:
if s.name == name:
return s
return None
@classmethod
def get_all(cls):
return Switch.switches
def set_state(self, state):
self.state = SwitchState.to_state(state)
def is_on(self):
return self.state