def __init__(self, config): self.relays = dict() self.boards = dict() self.devices = dict() validate_key('boards', config, list, 'relay config file') for elem in config['boards']: board = self.create_relay_board(elem) if board.name in self.boards: raise RelayConfigError( self.DUPLICATE_ID_ERR_MSG.format('name', elem['name'], elem)) self.boards[board.name] = board # Note: 'boards' is a necessary value, 'devices' is not. if 'devices' in config: for elem in config['devices']: relay_device = self.create_relay_device(elem) if relay_device.name in self.devices: raise RelayConfigError( self.DUPLICATE_ID_ERR_MSG.format( 'name', elem['name'], elem)) self.devices[relay_device.name] = relay_device else: device_config = dict() device_config['name'] = 'GenericRelayDevice' device_config['relays'] = dict() for relay_id in self.relays: device_config['relays'][relay_id] = relay_id self.devices['device'] = self.create_relay_device(device_config)
def __init__(self, config, relay_rig): GenericRelayDevice.__init__(self, config, relay_rig) self.mac_address = validate_key('mac_address', config, str, 'ak_xb10') for button in Buttons: self.ensure_config_contains_relay(button.value)
def __init__(self, config): # This will be lazy loaded self.status_dict = None self.base_url = validate_key('base_url', config, str, 'config') if not self.base_url.endswith('/'): self.base_url += '/' RelayBoard.__init__(self, config)
def __init__(self, config, relay_rig): GenericRelayDevice.__init__(self, config, relay_rig) self.mac_address = validate_key('mac_address', config, str, 'SingleButtonDongle') self.ensure_config_contains_relay(Buttons.ACTION.value)
def __init__(self, config): """Creates a RelayBoard instance. Handles naming and relay creation. Args: config: A configuration dictionary, usually pulled from an element under in "boards" list in the relay rig config file. """ self.name = validate_key('name', config, str, 'config') if '/' in self.name: raise RelayConfigError('RelayBoard name cannot contain a "/".') self.relays = dict() for pos in self.get_relay_position_list(): self.relays[pos] = Relay(self, pos)
def create_relay_board(self, config): """Builds a RelayBoard from the given config. Args: config: An object containing 'type', 'name', 'relays', and (optionally) 'properties'. See the example json file. Returns: A RelayBoard with the given type found in the config. Raises: RelayConfigError if config['type'] doesn't exist or is not a string. """ validate_key('type', config, str, '"boards" element') try: ret = self._board_constructors[config['type']](config) except LookupError: raise RelayConfigError( 'RelayBoard with type {} not found. Has it been added ' 'to the _board_constructors dict?'.format(config['type'])) for _, relay in ret.relays.items(): self.relays[relay.relay_id] = relay return ret
def __init__(self, config, relay_rig): """Creates a RelayDevice. Args: config: The dictionary found in the config file for this device. You can add your own params to the config file if needed, and they will be found in this dictionary. relay_rig: The RelayRig the device is attached to. This won't be useful for classes that inherit from RelayDevice, so just pass it down to this __init__. """ self.rig = relay_rig self.relays = dict() validate_key('name', config, str, '"devices" element') self.name = config['name'] relays = validate_key('relays', config, dict, '"devices" list element') if len(relays) < 1: raise RelayConfigError( 'Key "relays" must have at least 1 element.') for name, relay_id in relays.items(): self.relays[name] = relay_rig.relays[relay_id]
def __init__(self, config, relay_rig): GenericRelayDevice.__init__(self, config, relay_rig) self.mac_address = validate_key('mac_address', config, str, self.__class__.__name__)