repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device.get_engine_version
def get_engine_version(self): """Get the device engine version.""" msg = StandardSend(self._address, COMMAND_GET_INSTEON_ENGINE_VERSION_0X0D_0X00) self._send_msg(msg)
python
def get_engine_version(self): """Get the device engine version.""" msg = StandardSend(self._address, COMMAND_GET_INSTEON_ENGINE_VERSION_0X0D_0X00) self._send_msg(msg)
[ "def", "get_engine_version", "(", "self", ")", ":", "msg", "=", "StandardSend", "(", "self", ".", "_address", ",", "COMMAND_GET_INSTEON_ENGINE_VERSION_0X0D_0X00", ")", "self", ".", "_send_msg", "(", "msg", ")" ]
Get the device engine version.
[ "Get", "the", "device", "engine", "version", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L266-L270
train
39,300
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device.ping
def ping(self): """Ping a device.""" msg = StandardSend(self._address, COMMAND_PING_0X0F_0X00) self._send_msg(msg)
python
def ping(self): """Ping a device.""" msg = StandardSend(self._address, COMMAND_PING_0X0F_0X00) self._send_msg(msg)
[ "def", "ping", "(", "self", ")", ":", "msg", "=", "StandardSend", "(", "self", ".", "_address", ",", "COMMAND_PING_0X0F_0X00", ")", "self", ".", "_send_msg", "(", "msg", ")" ]
Ping a device.
[ "Ping", "a", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L272-L275
train
39,301
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device.create_default_links
def create_default_links(self): """Create the default links between the IM and the device.""" self._plm.manage_aldb_record(0x40, 0xe2, 0x00, self.address, self.cat, self.subcat, self.product_key) self.manage_aldb_record(0x41, 0xa2, 0x00, self._plm.address, self._plm.cat, self._plm.subcat, self._plm.product_key) for link in self._stateList: state = self._stateList[link] if state.is_responder: # IM is controller self._plm.manage_aldb_record(0x40, 0xe2, link, self._address, 0x00, 0x00, 0x00) # Device is responder self.manage_aldb_record(0x41, 0xa2, link, self._plm.address, state.linkdata1, state.linkdata2, state.linkdata3) if state.is_controller: # IM is responder self._plm.manage_aldb_record(0x41, 0xa2, link, self._address, 0x00, 0x00, 0x00) # Device is controller self.manage_aldb_record(0x40, 0xe2, link, self._plm.address, 0x00, 0x00, 0x00) self.read_aldb()
python
def create_default_links(self): """Create the default links between the IM and the device.""" self._plm.manage_aldb_record(0x40, 0xe2, 0x00, self.address, self.cat, self.subcat, self.product_key) self.manage_aldb_record(0x41, 0xa2, 0x00, self._plm.address, self._plm.cat, self._plm.subcat, self._plm.product_key) for link in self._stateList: state = self._stateList[link] if state.is_responder: # IM is controller self._plm.manage_aldb_record(0x40, 0xe2, link, self._address, 0x00, 0x00, 0x00) # Device is responder self.manage_aldb_record(0x41, 0xa2, link, self._plm.address, state.linkdata1, state.linkdata2, state.linkdata3) if state.is_controller: # IM is responder self._plm.manage_aldb_record(0x41, 0xa2, link, self._address, 0x00, 0x00, 0x00) # Device is controller self.manage_aldb_record(0x40, 0xe2, link, self._plm.address, 0x00, 0x00, 0x00) self.read_aldb()
[ "def", "create_default_links", "(", "self", ")", ":", "self", ".", "_plm", ".", "manage_aldb_record", "(", "0x40", ",", "0xe2", ",", "0x00", ",", "self", ".", "address", ",", "self", ".", "cat", ",", "self", ".", "subcat", ",", "self", ".", "product_ke...
Create the default links between the IM and the device.
[ "Create", "the", "default", "links", "between", "the", "IM", "and", "the", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L277-L301
train
39,302
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device.read_aldb
def read_aldb(self, mem_addr=0x0000, num_recs=0): """Read the device All-Link Database.""" if self._aldb.version == ALDBVersion.Null: _LOGGER.info('Device %s does not contain an All-Link Database', self._address.human) else: _LOGGER.info('Reading All-Link Database for device %s', self._address.human) asyncio.ensure_future(self._aldb.load(mem_addr, num_recs), loop=self._plm.loop) self._aldb.add_loaded_callback(self._aldb_loaded_callback)
python
def read_aldb(self, mem_addr=0x0000, num_recs=0): """Read the device All-Link Database.""" if self._aldb.version == ALDBVersion.Null: _LOGGER.info('Device %s does not contain an All-Link Database', self._address.human) else: _LOGGER.info('Reading All-Link Database for device %s', self._address.human) asyncio.ensure_future(self._aldb.load(mem_addr, num_recs), loop=self._plm.loop) self._aldb.add_loaded_callback(self._aldb_loaded_callback)
[ "def", "read_aldb", "(", "self", ",", "mem_addr", "=", "0x0000", ",", "num_recs", "=", "0", ")", ":", "if", "self", ".", "_aldb", ".", "version", "==", "ALDBVersion", ".", "Null", ":", "_LOGGER", ".", "info", "(", "'Device %s does not contain an All-Link Dat...
Read the device All-Link Database.
[ "Read", "the", "device", "All", "-", "Link", "Database", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L303-L313
train
39,303
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device.write_aldb
def write_aldb(self, mem_addr: int, mode: str, group: int, target, data1=0x00, data2=0x00, data3=0x00): """Write to the device All-Link Database. Parameters: Required: mode: r - device is a responder of target c - device is a controller of target group: Link group target: Address of the other device Optional: data1: Device dependant data2: Device dependant data3: Device dependant """ if isinstance(mode, str) and mode.lower() in ['c', 'r']: pass else: _LOGGER.error('Insteon link mode: %s', mode) raise ValueError("Mode must be 'c' or 'r'") if isinstance(group, int): pass else: raise ValueError("Group must be an integer") target_addr = Address(target) _LOGGER.debug('calling aldb write_record') self._aldb.write_record(mem_addr, mode, group, target_addr, data1, data2, data3) self._aldb.add_loaded_callback(self._aldb_loaded_callback)
python
def write_aldb(self, mem_addr: int, mode: str, group: int, target, data1=0x00, data2=0x00, data3=0x00): """Write to the device All-Link Database. Parameters: Required: mode: r - device is a responder of target c - device is a controller of target group: Link group target: Address of the other device Optional: data1: Device dependant data2: Device dependant data3: Device dependant """ if isinstance(mode, str) and mode.lower() in ['c', 'r']: pass else: _LOGGER.error('Insteon link mode: %s', mode) raise ValueError("Mode must be 'c' or 'r'") if isinstance(group, int): pass else: raise ValueError("Group must be an integer") target_addr = Address(target) _LOGGER.debug('calling aldb write_record') self._aldb.write_record(mem_addr, mode, group, target_addr, data1, data2, data3) self._aldb.add_loaded_callback(self._aldb_loaded_callback)
[ "def", "write_aldb", "(", "self", ",", "mem_addr", ":", "int", ",", "mode", ":", "str", ",", "group", ":", "int", ",", "target", ",", "data1", "=", "0x00", ",", "data2", "=", "0x00", ",", "data3", "=", "0x00", ")", ":", "if", "isinstance", "(", "...
Write to the device All-Link Database. Parameters: Required: mode: r - device is a responder of target c - device is a controller of target group: Link group target: Address of the other device Optional: data1: Device dependant data2: Device dependant data3: Device dependant
[ "Write", "to", "the", "device", "All", "-", "Link", "Database", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L441-L473
train
39,304
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device.del_aldb
def del_aldb(self, mem_addr: int): """Delete an All-Link Database record.""" self._aldb.del_record(mem_addr) self._aldb.add_loaded_callback(self._aldb_loaded_callback)
python
def del_aldb(self, mem_addr: int): """Delete an All-Link Database record.""" self._aldb.del_record(mem_addr) self._aldb.add_loaded_callback(self._aldb_loaded_callback)
[ "def", "del_aldb", "(", "self", ",", "mem_addr", ":", "int", ")", ":", "self", ".", "_aldb", ".", "del_record", "(", "mem_addr", ")", "self", ".", "_aldb", ".", "add_loaded_callback", "(", "self", ".", "_aldb_loaded_callback", ")" ]
Delete an All-Link Database record.
[ "Delete", "an", "All", "-", "Link", "Database", "record", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L475-L478
train
39,305
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device._refresh_aldb_records
def _refresh_aldb_records(self, linkcode, address, group): """Refresh the IM and device ALDB records.""" if self.aldb.status in [ALDBStatus.LOADED, ALDBStatus.PARTIAL]: for mem_addr in self.aldb: rec = self.aldb[mem_addr] if linkcode in [0, 1, 3]: if rec.control_flags.is_high_water_mark: _LOGGER.debug('Removing HWM record %04x', mem_addr) self.aldb.pop(mem_addr) elif not rec.control_flags.is_in_use: _LOGGER.debug('Removing not in use record %04x', mem_addr) self.aldb.pop(mem_addr) else: if rec.address == self.address and rec.group == group: _LOGGER.debug('Removing record %04x with addr %s and ' 'group %d', mem_addr, rec.address, rec.group) self.aldb.pop(mem_addr) self.read_aldb()
python
def _refresh_aldb_records(self, linkcode, address, group): """Refresh the IM and device ALDB records.""" if self.aldb.status in [ALDBStatus.LOADED, ALDBStatus.PARTIAL]: for mem_addr in self.aldb: rec = self.aldb[mem_addr] if linkcode in [0, 1, 3]: if rec.control_flags.is_high_water_mark: _LOGGER.debug('Removing HWM record %04x', mem_addr) self.aldb.pop(mem_addr) elif not rec.control_flags.is_in_use: _LOGGER.debug('Removing not in use record %04x', mem_addr) self.aldb.pop(mem_addr) else: if rec.address == self.address and rec.group == group: _LOGGER.debug('Removing record %04x with addr %s and ' 'group %d', mem_addr, rec.address, rec.group) self.aldb.pop(mem_addr) self.read_aldb()
[ "def", "_refresh_aldb_records", "(", "self", ",", "linkcode", ",", "address", ",", "group", ")", ":", "if", "self", ".", "aldb", ".", "status", "in", "[", "ALDBStatus", ".", "LOADED", ",", "ALDBStatus", ".", "PARTIAL", "]", ":", "for", "mem_addr", "in", ...
Refresh the IM and device ALDB records.
[ "Refresh", "the", "IM", "and", "device", "ALDB", "records", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L537-L556
train
39,306
nugget/python-insteonplm
insteonplm/devices/__init__.py
Device.receive_message
def receive_message(self, msg): """Receive a messages sent to this device.""" _LOGGER.debug('Starting Device.receive_message') if hasattr(msg, 'isack') and msg.isack: _LOGGER.debug('Got Message ACK') if self._sent_msg_wait_for_directACK.get('callback') is not None: _LOGGER.debug('Look for direct ACK') asyncio.ensure_future(self._wait_for_direct_ACK(), loop=self._plm.loop) else: _LOGGER.debug('DA queue: %s', self._sent_msg_wait_for_directACK) _LOGGER.debug('Message ACK with no callback') if (hasattr(msg, 'flags') and hasattr(msg.flags, 'isDirectACK') and msg.flags.isDirectACK): _LOGGER.debug('Got Direct ACK message') if self._send_msg_lock.locked(): self._directACK_received_queue.put_nowait(msg) else: _LOGGER.debug('But Direct ACK not expected') if not self._is_duplicate(msg): callbacks = self._message_callbacks.get_callbacks_from_message(msg) for callback in callbacks: _LOGGER.debug('Scheduling msg callback: %s', callback) self._plm.loop.call_soon(callback, msg) else: _LOGGER.debug('msg is duplicate') _LOGGER.debug(msg) self._last_communication_received = datetime.datetime.now() _LOGGER.debug('Ending Device.receive_message')
python
def receive_message(self, msg): """Receive a messages sent to this device.""" _LOGGER.debug('Starting Device.receive_message') if hasattr(msg, 'isack') and msg.isack: _LOGGER.debug('Got Message ACK') if self._sent_msg_wait_for_directACK.get('callback') is not None: _LOGGER.debug('Look for direct ACK') asyncio.ensure_future(self._wait_for_direct_ACK(), loop=self._plm.loop) else: _LOGGER.debug('DA queue: %s', self._sent_msg_wait_for_directACK) _LOGGER.debug('Message ACK with no callback') if (hasattr(msg, 'flags') and hasattr(msg.flags, 'isDirectACK') and msg.flags.isDirectACK): _LOGGER.debug('Got Direct ACK message') if self._send_msg_lock.locked(): self._directACK_received_queue.put_nowait(msg) else: _LOGGER.debug('But Direct ACK not expected') if not self._is_duplicate(msg): callbacks = self._message_callbacks.get_callbacks_from_message(msg) for callback in callbacks: _LOGGER.debug('Scheduling msg callback: %s', callback) self._plm.loop.call_soon(callback, msg) else: _LOGGER.debug('msg is duplicate') _LOGGER.debug(msg) self._last_communication_received = datetime.datetime.now() _LOGGER.debug('Ending Device.receive_message')
[ "def", "receive_message", "(", "self", ",", "msg", ")", ":", "_LOGGER", ".", "debug", "(", "'Starting Device.receive_message'", ")", "if", "hasattr", "(", "msg", ",", "'isack'", ")", "and", "msg", ".", "isack", ":", "_LOGGER", ".", "debug", "(", "'Got Mess...
Receive a messages sent to this device.
[ "Receive", "a", "messages", "sent", "to", "this", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L666-L696
train
39,307
nugget/python-insteonplm
insteonplm/devices/__init__.py
X10Device.receive_message
def receive_message(self, msg): """Receive a message sent to this device.""" _LOGGER.debug('Starting X10Device.receive_message') if hasattr(msg, 'isack') and msg.isack: _LOGGER.debug('Got Message ACK') if self._send_msg_lock.locked(): self._send_msg_lock.release() callbacks = self._message_callbacks.get_callbacks_from_message(msg) _LOGGER.debug('Found %d callbacks for msg %s', len(callbacks), msg) for callback in callbacks: _LOGGER.debug('Scheduling msg callback: %s', callback) self._plm.loop.call_soon(callback, msg) self._last_communication_received = datetime.datetime.now() _LOGGER.debug('Ending Device.receive_message')
python
def receive_message(self, msg): """Receive a message sent to this device.""" _LOGGER.debug('Starting X10Device.receive_message') if hasattr(msg, 'isack') and msg.isack: _LOGGER.debug('Got Message ACK') if self._send_msg_lock.locked(): self._send_msg_lock.release() callbacks = self._message_callbacks.get_callbacks_from_message(msg) _LOGGER.debug('Found %d callbacks for msg %s', len(callbacks), msg) for callback in callbacks: _LOGGER.debug('Scheduling msg callback: %s', callback) self._plm.loop.call_soon(callback, msg) self._last_communication_received = datetime.datetime.now() _LOGGER.debug('Ending Device.receive_message')
[ "def", "receive_message", "(", "self", ",", "msg", ")", ":", "_LOGGER", ".", "debug", "(", "'Starting X10Device.receive_message'", ")", "if", "hasattr", "(", "msg", ",", "'isack'", ")", "and", "msg", ".", "isack", ":", "_LOGGER", ".", "debug", "(", "'Got M...
Receive a message sent to this device.
[ "Receive", "a", "message", "sent", "to", "this", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L851-L864
train
39,308
nugget/python-insteonplm
insteonplm/devices/__init__.py
StateList.add
def add(self, plm, device, stateType, stateName, group, defaultValue=None): """Add a state to the StateList.""" self._stateList[group] = stateType(plm, device, stateName, group, defaultValue=defaultValue)
python
def add(self, plm, device, stateType, stateName, group, defaultValue=None): """Add a state to the StateList.""" self._stateList[group] = stateType(plm, device, stateName, group, defaultValue=defaultValue)
[ "def", "add", "(", "self", ",", "plm", ",", "device", ",", "stateType", ",", "stateName", ",", "group", ",", "defaultValue", "=", "None", ")", ":", "self", ".", "_stateList", "[", "group", "]", "=", "stateType", "(", "plm", ",", "device", ",", "state...
Add a state to the StateList.
[ "Add", "a", "state", "to", "the", "StateList", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L922-L925
train
39,309
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDBRecord.create_from_userdata
def create_from_userdata(userdata): """Create ALDB Record from the userdata dictionary.""" memhi = userdata.get('d3') memlo = userdata.get('d4') memory = memhi << 8 | memlo control_flags = userdata.get('d6') group = userdata.get('d7') addrhi = userdata.get('d8') addrmed = userdata.get('d9') addrlo = userdata.get('d10') addr = Address(bytearray([addrhi, addrmed, addrlo])) data1 = userdata.get('d11') data2 = userdata.get('d12') data3 = userdata.get('d13') return ALDBRecord(memory, control_flags, group, addr, data1, data2, data3)
python
def create_from_userdata(userdata): """Create ALDB Record from the userdata dictionary.""" memhi = userdata.get('d3') memlo = userdata.get('d4') memory = memhi << 8 | memlo control_flags = userdata.get('d6') group = userdata.get('d7') addrhi = userdata.get('d8') addrmed = userdata.get('d9') addrlo = userdata.get('d10') addr = Address(bytearray([addrhi, addrmed, addrlo])) data1 = userdata.get('d11') data2 = userdata.get('d12') data3 = userdata.get('d13') return ALDBRecord(memory, control_flags, group, addr, data1, data2, data3)
[ "def", "create_from_userdata", "(", "userdata", ")", ":", "memhi", "=", "userdata", ".", "get", "(", "'d3'", ")", "memlo", "=", "userdata", ".", "get", "(", "'d4'", ")", "memory", "=", "memhi", "<<", "8", "|", "memlo", "control_flags", "=", "userdata", ...
Create ALDB Record from the userdata dictionary.
[ "Create", "ALDB", "Record", "from", "the", "userdata", "dictionary", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1009-L1024
train
39,310
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDBRecord.to_userdata
def to_userdata(self): """Return a Userdata dictionary.""" userdata = Userdata({'d3': self.memhi, 'd4': self.memlo, 'd6': self.control_flags, 'd7': self.group, 'd8': self.address.bytes[2], 'd9': self.address.bytes[1], 'd10': self.address.bytes[0], 'd11': self.data1, 'd12': self.data2, 'd13': self.data3}) return userdata
python
def to_userdata(self): """Return a Userdata dictionary.""" userdata = Userdata({'d3': self.memhi, 'd4': self.memlo, 'd6': self.control_flags, 'd7': self.group, 'd8': self.address.bytes[2], 'd9': self.address.bytes[1], 'd10': self.address.bytes[0], 'd11': self.data1, 'd12': self.data2, 'd13': self.data3}) return userdata
[ "def", "to_userdata", "(", "self", ")", ":", "userdata", "=", "Userdata", "(", "{", "'d3'", ":", "self", ".", "memhi", ",", "'d4'", ":", "self", ".", "memlo", ",", "'d6'", ":", "self", ".", "control_flags", ",", "'d7'", ":", "self", ".", "group", "...
Return a Userdata dictionary.
[ "Return", "a", "Userdata", "dictionary", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1026-L1038
train
39,311
nugget/python-insteonplm
insteonplm/devices/__init__.py
ControlFlags.byte
def byte(self): """Return a byte representation of ControlFlags.""" flags = int(self._in_use) << 7 \ | int(self._controller) << 6 \ | int(self._bit5) << 5 \ | int(self._bit4) << 4 \ | int(self._used_before) << 1 return flags
python
def byte(self): """Return a byte representation of ControlFlags.""" flags = int(self._in_use) << 7 \ | int(self._controller) << 6 \ | int(self._bit5) << 5 \ | int(self._bit4) << 4 \ | int(self._used_before) << 1 return flags
[ "def", "byte", "(", "self", ")", ":", "flags", "=", "int", "(", "self", ".", "_in_use", ")", "<<", "7", "|", "int", "(", "self", ".", "_controller", ")", "<<", "6", "|", "int", "(", "self", ".", "_bit5", ")", "<<", "5", "|", "int", "(", "self...
Return a byte representation of ControlFlags.
[ "Return", "a", "byte", "representation", "of", "ControlFlags", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1099-L1106
train
39,312
nugget/python-insteonplm
insteonplm/devices/__init__.py
ControlFlags.create_from_byte
def create_from_byte(control_flags): """Create a ControlFlags class from a control flags byte.""" in_use = bool(control_flags & 1 << 7) controller = bool(control_flags & 1 << 6) bit5 = bool(control_flags & 1 << 5) bit4 = bool(control_flags & 1 << 4) used_before = bool(control_flags & 1 << 1) flags = ControlFlags(in_use, controller, used_before, bit5=bit5, bit4=bit4) return flags
python
def create_from_byte(control_flags): """Create a ControlFlags class from a control flags byte.""" in_use = bool(control_flags & 1 << 7) controller = bool(control_flags & 1 << 6) bit5 = bool(control_flags & 1 << 5) bit4 = bool(control_flags & 1 << 4) used_before = bool(control_flags & 1 << 1) flags = ControlFlags(in_use, controller, used_before, bit5=bit5, bit4=bit4) return flags
[ "def", "create_from_byte", "(", "control_flags", ")", ":", "in_use", "=", "bool", "(", "control_flags", "&", "1", "<<", "7", ")", "controller", "=", "bool", "(", "control_flags", "&", "1", "<<", "6", ")", "bit5", "=", "bool", "(", "control_flags", "&", ...
Create a ControlFlags class from a control flags byte.
[ "Create", "a", "ControlFlags", "class", "from", "a", "control", "flags", "byte", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1109-L1118
train
39,313
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDB.add_loaded_callback
def add_loaded_callback(self, callback): """Add a callback to be run when the ALDB load is complete.""" if callback not in self._cb_aldb_loaded: self._cb_aldb_loaded.append(callback)
python
def add_loaded_callback(self, callback): """Add a callback to be run when the ALDB load is complete.""" if callback not in self._cb_aldb_loaded: self._cb_aldb_loaded.append(callback)
[ "def", "add_loaded_callback", "(", "self", ",", "callback", ")", ":", "if", "callback", "not", "in", "self", ".", "_cb_aldb_loaded", ":", "self", ".", "_cb_aldb_loaded", ".", "append", "(", "callback", ")" ]
Add a callback to be run when the ALDB load is complete.
[ "Add", "a", "callback", "to", "be", "run", "when", "the", "ALDB", "load", "is", "complete", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1207-L1210
train
39,314
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDB.load
async def load(self, mem_addr=0x0000, rec_count=0, retry=0): """Read the device database and load.""" if self._version == ALDBVersion.Null: self._status = ALDBStatus.LOADED _LOGGER.debug('Device has no ALDB') else: self._status = ALDBStatus.LOADING _LOGGER.debug('Tring to lock from load') await self._rec_mgr_lock _LOGGER.debug('load yielded lock') mem_hi = mem_addr >> 8 mem_lo = mem_addr & 0xff log_output = 'ALDB read' max_retries = 0 if rec_count: max_retries = ALDB_RECORD_RETRIES if mem_addr == 0x0000: log_output = '{:s} first record'.format(log_output) else: log_output = '{:s} record {:04x}'.format(log_output, mem_addr) else: max_retries = ALDB_ALL_RECORD_RETRIES log_output = '{:s} all records'.format(log_output) if retry: log_output = '{:s} retry {:d} of {:d}'.format(log_output, retry, max_retries) _LOGGER.info(log_output) userdata = Userdata({'d1': 0, 'd2': 0, 'd3': mem_hi, 'd4': mem_lo, 'd5': rec_count}) msg = ExtendedSend(self._address, COMMAND_EXTENDED_READ_WRITE_ALDB_0X2F_0X00, userdata=userdata) msg.set_checksum() self._send_method(msg, self._handle_read_aldb_ack, True) if not self._load_action: self._set_load_action(mem_addr, rec_count, -1, False)
python
async def load(self, mem_addr=0x0000, rec_count=0, retry=0): """Read the device database and load.""" if self._version == ALDBVersion.Null: self._status = ALDBStatus.LOADED _LOGGER.debug('Device has no ALDB') else: self._status = ALDBStatus.LOADING _LOGGER.debug('Tring to lock from load') await self._rec_mgr_lock _LOGGER.debug('load yielded lock') mem_hi = mem_addr >> 8 mem_lo = mem_addr & 0xff log_output = 'ALDB read' max_retries = 0 if rec_count: max_retries = ALDB_RECORD_RETRIES if mem_addr == 0x0000: log_output = '{:s} first record'.format(log_output) else: log_output = '{:s} record {:04x}'.format(log_output, mem_addr) else: max_retries = ALDB_ALL_RECORD_RETRIES log_output = '{:s} all records'.format(log_output) if retry: log_output = '{:s} retry {:d} of {:d}'.format(log_output, retry, max_retries) _LOGGER.info(log_output) userdata = Userdata({'d1': 0, 'd2': 0, 'd3': mem_hi, 'd4': mem_lo, 'd5': rec_count}) msg = ExtendedSend(self._address, COMMAND_EXTENDED_READ_WRITE_ALDB_0X2F_0X00, userdata=userdata) msg.set_checksum() self._send_method(msg, self._handle_read_aldb_ack, True) if not self._load_action: self._set_load_action(mem_addr, rec_count, -1, False)
[ "async", "def", "load", "(", "self", ",", "mem_addr", "=", "0x0000", ",", "rec_count", "=", "0", ",", "retry", "=", "0", ")", ":", "if", "self", ".", "_version", "==", "ALDBVersion", ".", "Null", ":", "self", ".", "_status", "=", "ALDBStatus", ".", ...
Read the device database and load.
[ "Read", "the", "device", "database", "and", "load", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1212-L1255
train
39,315
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDB.find_matching_link
def find_matching_link(self, mode, group, addr): """Find a matching link in the current device. Mode: r | c is the mode of the link in the linked device This method will search for a corresponding link in the reverse direction. group: All-Link group number addr: Inteon address of the linked device """ found_rec = None mode_test = None if mode.lower() in ['c', 'r']: link_group = int(group) link_addr = Address(addr) for mem_addr in self: rec = self[mem_addr] if mode.lower() == 'r': mode_test = rec.control_flags.is_controller else: mode_test = rec.control_flags.is_responder if (mode_test and rec.group == link_group and rec.address == link_addr): found_rec = rec return found_rec
python
def find_matching_link(self, mode, group, addr): """Find a matching link in the current device. Mode: r | c is the mode of the link in the linked device This method will search for a corresponding link in the reverse direction. group: All-Link group number addr: Inteon address of the linked device """ found_rec = None mode_test = None if mode.lower() in ['c', 'r']: link_group = int(group) link_addr = Address(addr) for mem_addr in self: rec = self[mem_addr] if mode.lower() == 'r': mode_test = rec.control_flags.is_controller else: mode_test = rec.control_flags.is_responder if (mode_test and rec.group == link_group and rec.address == link_addr): found_rec = rec return found_rec
[ "def", "find_matching_link", "(", "self", ",", "mode", ",", "group", ",", "addr", ")", ":", "found_rec", "=", "None", "mode_test", "=", "None", "if", "mode", ".", "lower", "(", ")", "in", "[", "'c'", ",", "'r'", "]", ":", "link_group", "=", "int", ...
Find a matching link in the current device. Mode: r | c is the mode of the link in the linked device This method will search for a corresponding link in the reverse direction. group: All-Link group number addr: Inteon address of the linked device
[ "Find", "a", "matching", "link", "in", "the", "current", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1347-L1371
train
39,316
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDB.record_received
def record_received(self, msg): """Handle ALDB record received from device.""" release_lock = False userdata = msg.userdata rec = ALDBRecord.create_from_userdata(userdata) self._records[rec.mem_addr] = rec _LOGGER.debug('ALDB Record: %s', rec) rec_count = self._load_action.rec_count if rec_count == 1 or self._have_all_records(): release_lock = True if self._is_first_record(rec): self._mem_addr = rec.mem_addr if release_lock and self._rec_mgr_lock.locked(): _LOGGER.debug('Releasing lock because record received') self._rec_mgr_lock.release()
python
def record_received(self, msg): """Handle ALDB record received from device.""" release_lock = False userdata = msg.userdata rec = ALDBRecord.create_from_userdata(userdata) self._records[rec.mem_addr] = rec _LOGGER.debug('ALDB Record: %s', rec) rec_count = self._load_action.rec_count if rec_count == 1 or self._have_all_records(): release_lock = True if self._is_first_record(rec): self._mem_addr = rec.mem_addr if release_lock and self._rec_mgr_lock.locked(): _LOGGER.debug('Releasing lock because record received') self._rec_mgr_lock.release()
[ "def", "record_received", "(", "self", ",", "msg", ")", ":", "release_lock", "=", "False", "userdata", "=", "msg", ".", "userdata", "rec", "=", "ALDBRecord", ".", "create_from_userdata", "(", "userdata", ")", "self", ".", "_records", "[", "rec", ".", "mem_...
Handle ALDB record received from device.
[ "Handle", "ALDB", "record", "received", "from", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1373-L1391
train
39,317
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDB.load_saved_records
def load_saved_records(self, status, records): """Load ALDB records from a set of saved records.""" if isinstance(status, ALDBStatus): self._status = status else: self._status = ALDBStatus(status) for mem_addr in records: rec = records[mem_addr] control_flags = int(rec.get('control_flags', 0)) group = int(rec.get('group', 0)) rec_addr = rec.get('address', '000000') data1 = int(rec.get('data1', 0)) data2 = int(rec.get('data2', 0)) data3 = int(rec.get('data3', 0)) self[int(mem_addr)] = ALDBRecord(int(mem_addr), control_flags, group, rec_addr, data1, data2, data3) if self._status == ALDBStatus.LOADED: keys = list(self._records.keys()) keys.sort(reverse=True) first_key = keys[0] self._mem_addr = first_key
python
def load_saved_records(self, status, records): """Load ALDB records from a set of saved records.""" if isinstance(status, ALDBStatus): self._status = status else: self._status = ALDBStatus(status) for mem_addr in records: rec = records[mem_addr] control_flags = int(rec.get('control_flags', 0)) group = int(rec.get('group', 0)) rec_addr = rec.get('address', '000000') data1 = int(rec.get('data1', 0)) data2 = int(rec.get('data2', 0)) data3 = int(rec.get('data3', 0)) self[int(mem_addr)] = ALDBRecord(int(mem_addr), control_flags, group, rec_addr, data1, data2, data3) if self._status == ALDBStatus.LOADED: keys = list(self._records.keys()) keys.sort(reverse=True) first_key = keys[0] self._mem_addr = first_key
[ "def", "load_saved_records", "(", "self", ",", "status", ",", "records", ")", ":", "if", "isinstance", "(", "status", ",", "ALDBStatus", ")", ":", "self", ".", "_status", "=", "status", "else", ":", "self", ".", "_status", "=", "ALDBStatus", "(", "status...
Load ALDB records from a set of saved records.
[ "Load", "ALDB", "records", "from", "a", "set", "of", "saved", "records", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1393-L1414
train
39,318
nugget/python-insteonplm
insteonplm/devices/__init__.py
ALDB._set_load_action
def _set_load_action(self, mem_addr, rec_count, retries, read_complete=False): """Calculate the next record to read. If the last record was successful and one record was being read then look for the next record until we get to the high water mark. If the last read was successful and all records were being read then look for the first record. if the last read was unsuccessful and one record was being read then repeat the last read until max retries If the last read was unsuccessful and all records were being read then repeat the last read until max retries or look for the first record. """ if self._have_all_records(): mem_addr = None rec_count = 0 retries = 0 elif read_complete: retries = 0 if rec_count: mem_addr = self._next_address(mem_addr) else: mem_addr = self._next_address(mem_addr) rec_count = 1 retries = 0 elif rec_count and retries < ALDB_RECORD_RETRIES: retries = retries + 1 elif not rec_count and retries < ALDB_ALL_RECORD_RETRIES: retries = retries + 1 elif not rec_count and retries >= ALDB_ALL_RECORD_RETRIES: mem_addr = self._next_address(mem_addr) rec_count = 1 retries = 0 else: mem_addr = None rec_count = 0 retries = 0 self._load_action = LoadAction(mem_addr, rec_count, retries) if mem_addr is not None: _LOGGER.debug('Load action: addr: %04x rec_count: %d retries: %d', self._load_action.mem_addr, self._load_action.rec_count, self._load_action.retries)
python
def _set_load_action(self, mem_addr, rec_count, retries, read_complete=False): """Calculate the next record to read. If the last record was successful and one record was being read then look for the next record until we get to the high water mark. If the last read was successful and all records were being read then look for the first record. if the last read was unsuccessful and one record was being read then repeat the last read until max retries If the last read was unsuccessful and all records were being read then repeat the last read until max retries or look for the first record. """ if self._have_all_records(): mem_addr = None rec_count = 0 retries = 0 elif read_complete: retries = 0 if rec_count: mem_addr = self._next_address(mem_addr) else: mem_addr = self._next_address(mem_addr) rec_count = 1 retries = 0 elif rec_count and retries < ALDB_RECORD_RETRIES: retries = retries + 1 elif not rec_count and retries < ALDB_ALL_RECORD_RETRIES: retries = retries + 1 elif not rec_count and retries >= ALDB_ALL_RECORD_RETRIES: mem_addr = self._next_address(mem_addr) rec_count = 1 retries = 0 else: mem_addr = None rec_count = 0 retries = 0 self._load_action = LoadAction(mem_addr, rec_count, retries) if mem_addr is not None: _LOGGER.debug('Load action: addr: %04x rec_count: %d retries: %d', self._load_action.mem_addr, self._load_action.rec_count, self._load_action.retries)
[ "def", "_set_load_action", "(", "self", ",", "mem_addr", ",", "rec_count", ",", "retries", ",", "read_complete", "=", "False", ")", ":", "if", "self", ".", "_have_all_records", "(", ")", ":", "mem_addr", "=", "None", "rec_count", "=", "0", "retries", "=", ...
Calculate the next record to read. If the last record was successful and one record was being read then look for the next record until we get to the high water mark. If the last read was successful and all records were being read then look for the first record. if the last read was unsuccessful and one record was being read then repeat the last read until max retries If the last read was unsuccessful and all records were being read then repeat the last read until max retries or look for the first record.
[ "Calculate", "the", "next", "record", "to", "read", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/__init__.py#L1497-L1543
train
39,319
nugget/python-insteonplm
insteonplm/states/__init__.py
State.register_updates
def register_updates(self, callback): """Register a callback to notify a listener of state changes.""" _LOGGER.debug("Registered callback for state: %s", self._stateName) self._observer_callbacks.append(callback)
python
def register_updates(self, callback): """Register a callback to notify a listener of state changes.""" _LOGGER.debug("Registered callback for state: %s", self._stateName) self._observer_callbacks.append(callback)
[ "def", "register_updates", "(", "self", ",", "callback", ")", ":", "_LOGGER", ".", "debug", "(", "\"Registered callback for state: %s\"", ",", "self", ".", "_stateName", ")", "self", ".", "_observer_callbacks", ".", "append", "(", "callback", ")" ]
Register a callback to notify a listener of state changes.
[ "Register", "a", "callback", "to", "notify", "a", "listener", "of", "state", "changes", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/__init__.py#L114-L117
train
39,320
nugget/python-insteonplm
insteonplm/states/__init__.py
State._update_subscribers
def _update_subscribers(self, val): """Save state value and notify listeners of the change.""" self._value = val for callback in self._observer_callbacks: callback(self._address, self._group, val)
python
def _update_subscribers(self, val): """Save state value and notify listeners of the change.""" self._value = val for callback in self._observer_callbacks: callback(self._address, self._group, val)
[ "def", "_update_subscribers", "(", "self", ",", "val", ")", ":", "self", ".", "_value", "=", "val", "for", "callback", "in", "self", ".", "_observer_callbacks", ":", "callback", "(", "self", ".", "_address", ",", "self", ".", "_group", ",", "val", ")" ]
Save state value and notify listeners of the change.
[ "Save", "state", "value", "and", "notify", "listeners", "of", "the", "change", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/__init__.py#L119-L123
train
39,321
nugget/python-insteonplm
insteonplm/messages/extendedReceive.py
ExtendedReceive.template
def template(cls, address=None, target=None, commandtuple=None, userdata=None, cmd2=-1, flags=None): """Create message template for callbacks.""" msgraw = bytearray([0x02, cls._code]) msgraw.extend(bytes(cls._receivedSize)) msg = ExtendedReceive.from_raw_message(msgraw) if commandtuple: cmd1 = commandtuple.get('cmd1') cmd2out = commandtuple.get('cmd2') else: cmd1 = None cmd2out = None if cmd2 is not -1: cmd2out = cmd2 msg._address = Address(address) msg._target = Address(target) msg._messageFlags = MessageFlags(flags) msg._cmd1 = cmd1 msg._cmd2 = cmd2out msg._userdata = Userdata.create_pattern(userdata) return msg
python
def template(cls, address=None, target=None, commandtuple=None, userdata=None, cmd2=-1, flags=None): """Create message template for callbacks.""" msgraw = bytearray([0x02, cls._code]) msgraw.extend(bytes(cls._receivedSize)) msg = ExtendedReceive.from_raw_message(msgraw) if commandtuple: cmd1 = commandtuple.get('cmd1') cmd2out = commandtuple.get('cmd2') else: cmd1 = None cmd2out = None if cmd2 is not -1: cmd2out = cmd2 msg._address = Address(address) msg._target = Address(target) msg._messageFlags = MessageFlags(flags) msg._cmd1 = cmd1 msg._cmd2 = cmd2out msg._userdata = Userdata.create_pattern(userdata) return msg
[ "def", "template", "(", "cls", ",", "address", "=", "None", ",", "target", "=", "None", ",", "commandtuple", "=", "None", ",", "userdata", "=", "None", ",", "cmd2", "=", "-", "1", ",", "flags", "=", "None", ")", ":", "msgraw", "=", "bytearray", "("...
Create message template for callbacks.
[ "Create", "message", "template", "for", "callbacks", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/extendedReceive.py#L58-L81
train
39,322
nugget/python-insteonplm
insteonplm/messages/extendedReceive.py
ExtendedReceive.targetLow
def targetLow(self): """Return the low byte of the target address field. Used in All-Link Cleanup messages. """ low_byte = None if self.target is not None and self._messageFlags.isBroadcast: low_byte = self.target.bytes[0] return low_byte
python
def targetLow(self): """Return the low byte of the target address field. Used in All-Link Cleanup messages. """ low_byte = None if self.target is not None and self._messageFlags.isBroadcast: low_byte = self.target.bytes[0] return low_byte
[ "def", "targetLow", "(", "self", ")", ":", "low_byte", "=", "None", "if", "self", ".", "target", "is", "not", "None", "and", "self", ".", "_messageFlags", ".", "isBroadcast", ":", "low_byte", "=", "self", ".", "target", ".", "bytes", "[", "0", "]", "...
Return the low byte of the target address field. Used in All-Link Cleanup messages.
[ "Return", "the", "low", "byte", "of", "the", "target", "address", "field", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/extendedReceive.py#L114-L122
train
39,323
nugget/python-insteonplm
insteonplm/states/dimmable.py
DimmableSwitch.set_level
def set_level(self, val): """Set the devive ON LEVEL.""" if val == 0: self.off() else: setlevel = 255 if val < 1: setlevel = val * 100 elif val <= 0xff: setlevel = val set_command = StandardSend( self._address, COMMAND_LIGHT_ON_0X11_NONE, cmd2=setlevel) self._send_method(set_command, self._on_message_received)
python
def set_level(self, val): """Set the devive ON LEVEL.""" if val == 0: self.off() else: setlevel = 255 if val < 1: setlevel = val * 100 elif val <= 0xff: setlevel = val set_command = StandardSend( self._address, COMMAND_LIGHT_ON_0X11_NONE, cmd2=setlevel) self._send_method(set_command, self._on_message_received)
[ "def", "set_level", "(", "self", ",", "val", ")", ":", "if", "val", "==", "0", ":", "self", ".", "off", "(", ")", "else", ":", "setlevel", "=", "255", "if", "val", "<", "1", ":", "setlevel", "=", "val", "*", "100", "elif", "val", "<=", "0xff", ...
Set the devive ON LEVEL.
[ "Set", "the", "devive", "ON", "LEVEL", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/dimmable.py#L193-L205
train
39,324
nugget/python-insteonplm
insteonplm/states/dimmable.py
DimmableSwitch_Fan.set_level
def set_level(self, val): """Set the fan speed.""" speed = self._value_to_fan_speed(val) if val == 0: self.off() else: set_command = ExtendedSend(self._address, COMMAND_LIGHT_ON_0X11_NONE, self._udata, cmd2=speed) set_command.set_checksum() self._send_method(set_command, self._on_message_received)
python
def set_level(self, val): """Set the fan speed.""" speed = self._value_to_fan_speed(val) if val == 0: self.off() else: set_command = ExtendedSend(self._address, COMMAND_LIGHT_ON_0X11_NONE, self._udata, cmd2=speed) set_command.set_checksum() self._send_method(set_command, self._on_message_received)
[ "def", "set_level", "(", "self", ",", "val", ")", ":", "speed", "=", "self", ".", "_value_to_fan_speed", "(", "val", ")", "if", "val", "==", "0", ":", "self", ".", "off", "(", ")", "else", ":", "set_command", "=", "ExtendedSend", "(", "self", ".", ...
Set the fan speed.
[ "Set", "the", "fan", "speed", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/dimmable.py#L269-L279
train
39,325
nugget/python-insteonplm
insteonplm/states/cover.py
Cover.open
def open(self): """Turn the device ON.""" open_command = StandardSend(self._address, COMMAND_LIGHT_ON_0X11_NONE, cmd2=0xff) self._send_method(open_command, self._open_message_received)
python
def open(self): """Turn the device ON.""" open_command = StandardSend(self._address, COMMAND_LIGHT_ON_0X11_NONE, cmd2=0xff) self._send_method(open_command, self._open_message_received)
[ "def", "open", "(", "self", ")", ":", "open_command", "=", "StandardSend", "(", "self", ".", "_address", ",", "COMMAND_LIGHT_ON_0X11_NONE", ",", "cmd2", "=", "0xff", ")", "self", ".", "_send_method", "(", "open_command", ",", "self", ".", "_open_message_receiv...
Turn the device ON.
[ "Turn", "the", "device", "ON", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/cover.py#L108-L112
train
39,326
nugget/python-insteonplm
insteonplm/states/cover.py
Cover.open_fast
def open_fast(self): """Turn the device ON Fast.""" open_command = StandardSend(self._address, COMMAND_LIGHT_ON_FAST_0X12_NONE, cmd2=0xff) self._send_method(open_command, self._open_message_received)
python
def open_fast(self): """Turn the device ON Fast.""" open_command = StandardSend(self._address, COMMAND_LIGHT_ON_FAST_0X12_NONE, cmd2=0xff) self._send_method(open_command, self._open_message_received)
[ "def", "open_fast", "(", "self", ")", ":", "open_command", "=", "StandardSend", "(", "self", ".", "_address", ",", "COMMAND_LIGHT_ON_FAST_0X12_NONE", ",", "cmd2", "=", "0xff", ")", "self", ".", "_send_method", "(", "open_command", ",", "self", ".", "_open_mess...
Turn the device ON Fast.
[ "Turn", "the", "device", "ON", "Fast", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/cover.py#L114-L118
train
39,327
nugget/python-insteonplm
insteonplm/devices/climateControl.py
ClimateControl_2441th.async_refresh_state
def async_refresh_state(self): """Request each state to provide status update.""" _LOGGER.debug('Setting up extended status') ext_status = ExtendedSend( address=self._address, commandtuple=COMMAND_EXTENDED_GET_SET_0X2E_0X00, cmd2=0x02, userdata=Userdata()) ext_status.set_crc() _LOGGER.debug('Sending ext status: %s', ext_status) self._send_msg(ext_status) _LOGGER.debug('Sending temp status request') self.temperature.async_refresh_state()
python
def async_refresh_state(self): """Request each state to provide status update.""" _LOGGER.debug('Setting up extended status') ext_status = ExtendedSend( address=self._address, commandtuple=COMMAND_EXTENDED_GET_SET_0X2E_0X00, cmd2=0x02, userdata=Userdata()) ext_status.set_crc() _LOGGER.debug('Sending ext status: %s', ext_status) self._send_msg(ext_status) _LOGGER.debug('Sending temp status request') self.temperature.async_refresh_state()
[ "def", "async_refresh_state", "(", "self", ")", ":", "_LOGGER", ".", "debug", "(", "'Setting up extended status'", ")", "ext_status", "=", "ExtendedSend", "(", "address", "=", "self", ".", "_address", ",", "commandtuple", "=", "COMMAND_EXTENDED_GET_SET_0X2E_0X00", "...
Request each state to provide status update.
[ "Request", "each", "state", "to", "provide", "status", "update", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/climateControl.py#L86-L98
train
39,328
nugget/python-insteonplm
insteonplm/utils.py
byte_to_housecode
def byte_to_housecode(bytecode): """Return an X10 housecode value from a byte value.""" hc = list(HC_LOOKUP.keys())[list(HC_LOOKUP.values()).index(bytecode)] return hc.upper()
python
def byte_to_housecode(bytecode): """Return an X10 housecode value from a byte value.""" hc = list(HC_LOOKUP.keys())[list(HC_LOOKUP.values()).index(bytecode)] return hc.upper()
[ "def", "byte_to_housecode", "(", "bytecode", ")", ":", "hc", "=", "list", "(", "HC_LOOKUP", ".", "keys", "(", ")", ")", "[", "list", "(", "HC_LOOKUP", ".", "values", "(", ")", ")", ".", "index", "(", "bytecode", ")", "]", "return", "hc", ".", "uppe...
Return an X10 housecode value from a byte value.
[ "Return", "an", "X10", "housecode", "value", "from", "a", "byte", "value", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/utils.py#L22-L25
train
39,329
nugget/python-insteonplm
insteonplm/utils.py
byte_to_unitcode
def byte_to_unitcode(bytecode): """Return an X10 unitcode value from a byte value.""" return list(UC_LOOKUP.keys())[list(UC_LOOKUP.values()).index(bytecode)]
python
def byte_to_unitcode(bytecode): """Return an X10 unitcode value from a byte value.""" return list(UC_LOOKUP.keys())[list(UC_LOOKUP.values()).index(bytecode)]
[ "def", "byte_to_unitcode", "(", "bytecode", ")", ":", "return", "list", "(", "UC_LOOKUP", ".", "keys", "(", ")", ")", "[", "list", "(", "UC_LOOKUP", ".", "values", "(", ")", ")", ".", "index", "(", "bytecode", ")", "]" ]
Return an X10 unitcode value from a byte value.
[ "Return", "an", "X10", "unitcode", "value", "from", "a", "byte", "value", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/utils.py#L28-L30
train
39,330
nugget/python-insteonplm
insteonplm/utils.py
x10_command_type
def x10_command_type(command): """Return the X10 command type from an X10 command.""" command_type = X10CommandType.DIRECT if command in [X10_COMMAND_ALL_UNITS_OFF, X10_COMMAND_ALL_LIGHTS_ON, X10_COMMAND_ALL_LIGHTS_OFF]: command_type = X10CommandType.BROADCAST return command_type
python
def x10_command_type(command): """Return the X10 command type from an X10 command.""" command_type = X10CommandType.DIRECT if command in [X10_COMMAND_ALL_UNITS_OFF, X10_COMMAND_ALL_LIGHTS_ON, X10_COMMAND_ALL_LIGHTS_OFF]: command_type = X10CommandType.BROADCAST return command_type
[ "def", "x10_command_type", "(", "command", ")", ":", "command_type", "=", "X10CommandType", ".", "DIRECT", "if", "command", "in", "[", "X10_COMMAND_ALL_UNITS_OFF", ",", "X10_COMMAND_ALL_LIGHTS_ON", ",", "X10_COMMAND_ALL_LIGHTS_OFF", "]", ":", "command_type", "=", "X10...
Return the X10 command type from an X10 command.
[ "Return", "the", "X10", "command", "type", "from", "an", "X10", "command", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/utils.py#L33-L40
train
39,331
nugget/python-insteonplm
insteonplm/utils.py
set_bit
def set_bit(bitmask, bit, is_on): """Set the value of a bit in a bitmask on or off. Uses the low bit is 1 and the high bit is 8. """ bitshift = bit - 1 if is_on: return bitmask | (1 << bitshift) return bitmask & (0xff & ~(1 << bitshift))
python
def set_bit(bitmask, bit, is_on): """Set the value of a bit in a bitmask on or off. Uses the low bit is 1 and the high bit is 8. """ bitshift = bit - 1 if is_on: return bitmask | (1 << bitshift) return bitmask & (0xff & ~(1 << bitshift))
[ "def", "set_bit", "(", "bitmask", ",", "bit", ",", "is_on", ")", ":", "bitshift", "=", "bit", "-", "1", "if", "is_on", ":", "return", "bitmask", "|", "(", "1", "<<", "bitshift", ")", "return", "bitmask", "&", "(", "0xff", "&", "~", "(", "1", "<<"...
Set the value of a bit in a bitmask on or off. Uses the low bit is 1 and the high bit is 8.
[ "Set", "the", "value", "of", "a", "bit", "in", "a", "bitmask", "on", "or", "off", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/utils.py#L58-L66
train
39,332
nugget/python-insteonplm
insteonplm/messages/extendedSend.py
ExtendedSend.template
def template(cls, address=None, commandtuple=None, userdata=None, cmd2=-1, flags=None, acknak=None): """Create a message template used for callbacks.""" msgraw = bytearray([0x02, cls._code]) msgraw.extend(bytes(cls._receivedSize)) msg = ExtendedSend.from_raw_message(msgraw) if commandtuple: cmd1 = commandtuple.get('cmd1') cmd2out = commandtuple.get('cmd2') else: cmd1 = None cmd2out = None if cmd2 is not -1: cmd2out = cmd2 msg._address = Address(address) msg._messageFlags = MessageFlags(flags) msg._messageFlags.extended = 1 msg._cmd1 = cmd1 msg._cmd2 = cmd2out msg._userdata = Userdata.template(userdata) msg._acknak = acknak return msg
python
def template(cls, address=None, commandtuple=None, userdata=None, cmd2=-1, flags=None, acknak=None): """Create a message template used for callbacks.""" msgraw = bytearray([0x02, cls._code]) msgraw.extend(bytes(cls._receivedSize)) msg = ExtendedSend.from_raw_message(msgraw) if commandtuple: cmd1 = commandtuple.get('cmd1') cmd2out = commandtuple.get('cmd2') else: cmd1 = None cmd2out = None if cmd2 is not -1: cmd2out = cmd2 msg._address = Address(address) msg._messageFlags = MessageFlags(flags) msg._messageFlags.extended = 1 msg._cmd1 = cmd1 msg._cmd2 = cmd2out msg._userdata = Userdata.template(userdata) msg._acknak = acknak return msg
[ "def", "template", "(", "cls", ",", "address", "=", "None", ",", "commandtuple", "=", "None", ",", "userdata", "=", "None", ",", "cmd2", "=", "-", "1", ",", "flags", "=", "None", ",", "acknak", "=", "None", ")", ":", "msgraw", "=", "bytearray", "("...
Create a message template used for callbacks.
[ "Create", "a", "message", "template", "used", "for", "callbacks", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/extendedSend.py#L69-L93
train
39,333
nugget/python-insteonplm
insteonplm/messages/extendedSend.py
ExtendedSend.set_checksum
def set_checksum(self): """Set byte 14 of the userdata to a checksum value.""" data_sum = self.cmd1 + self.cmd2 for i in range(1, 14): data_sum += self._userdata['d{:d}'.format(i)] chksum = 0xff - (data_sum & 0xff) + 1 self._userdata['d14'] = chksum
python
def set_checksum(self): """Set byte 14 of the userdata to a checksum value.""" data_sum = self.cmd1 + self.cmd2 for i in range(1, 14): data_sum += self._userdata['d{:d}'.format(i)] chksum = 0xff - (data_sum & 0xff) + 1 self._userdata['d14'] = chksum
[ "def", "set_checksum", "(", "self", ")", ":", "data_sum", "=", "self", ".", "cmd1", "+", "self", ".", "cmd2", "for", "i", "in", "range", "(", "1", ",", "14", ")", ":", "data_sum", "+=", "self", ".", "_userdata", "[", "'d{:d}'", ".", "format", "(", ...
Set byte 14 of the userdata to a checksum value.
[ "Set", "byte", "14", "of", "the", "userdata", "to", "a", "checksum", "value", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/extendedSend.py#L143-L149
train
39,334
nugget/python-insteonplm
insteonplm/messages/standardReceive.py
StandardReceive.from_raw_message
def from_raw_message(cls, rawmessage): """Create message from a raw byte stream.""" return StandardReceive(rawmessage[2:5], rawmessage[5:8], {'cmd1': rawmessage[9], 'cmd2': rawmessage[10]}, flags=rawmessage[8])
python
def from_raw_message(cls, rawmessage): """Create message from a raw byte stream.""" return StandardReceive(rawmessage[2:5], rawmessage[5:8], {'cmd1': rawmessage[9], 'cmd2': rawmessage[10]}, flags=rawmessage[8])
[ "def", "from_raw_message", "(", "cls", ",", "rawmessage", ")", ":", "return", "StandardReceive", "(", "rawmessage", "[", "2", ":", "5", "]", ",", "rawmessage", "[", "5", ":", "8", "]", ",", "{", "'cmd1'", ":", "rawmessage", "[", "9", "]", ",", "'cmd2...
Create message from a raw byte stream.
[ "Create", "message", "from", "a", "raw", "byte", "stream", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/standardReceive.py#L43-L49
train
39,335
nugget/python-insteonplm
insteonplm/messages/standardReceive.py
StandardReceive.targetMed
def targetMed(self): """Return the middle byte of the target message property. Used in All-Link Cleanup message types. """ med_byte = None if self.target.addr is not None and self._messageFlags.isBroadcast: med_byte = self.target.bytes[1] return med_byte
python
def targetMed(self): """Return the middle byte of the target message property. Used in All-Link Cleanup message types. """ med_byte = None if self.target.addr is not None and self._messageFlags.isBroadcast: med_byte = self.target.bytes[1] return med_byte
[ "def", "targetMed", "(", "self", ")", ":", "med_byte", "=", "None", "if", "self", ".", "target", ".", "addr", "is", "not", "None", "and", "self", ".", "_messageFlags", ".", "isBroadcast", ":", "med_byte", "=", "self", ".", "target", ".", "bytes", "[", ...
Return the middle byte of the target message property. Used in All-Link Cleanup message types.
[ "Return", "the", "middle", "byte", "of", "the", "target", "message", "property", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/standardReceive.py#L114-L122
train
39,336
nugget/python-insteonplm
insteonplm/messages/standardReceive.py
StandardReceive.targetHi
def targetHi(self): """Return the high byte of the target message property. Used in All-Link Cleanup message types. """ hi_byte = None if self.target.addr is not None and self._messageFlags.isBroadcast: hi_byte = self.target.bytes[2] return hi_byte
python
def targetHi(self): """Return the high byte of the target message property. Used in All-Link Cleanup message types. """ hi_byte = None if self.target.addr is not None and self._messageFlags.isBroadcast: hi_byte = self.target.bytes[2] return hi_byte
[ "def", "targetHi", "(", "self", ")", ":", "hi_byte", "=", "None", "if", "self", ".", "target", ".", "addr", "is", "not", "None", "and", "self", ".", "_messageFlags", ".", "isBroadcast", ":", "hi_byte", "=", "self", ".", "target", ".", "bytes", "[", "...
Return the high byte of the target message property. Used in All-Link Cleanup message types.
[ "Return", "the", "high", "byte", "of", "the", "target", "message", "property", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/standardReceive.py#L125-L133
train
39,337
nugget/python-insteonplm
insteonplm/messages/__init__.py
create
def create(rawmessage): """Return an INSTEON message class based on a raw byte stream.""" rawmessage = _trim_buffer_garbage(rawmessage) if len(rawmessage) < 2: return (None, rawmessage) code = rawmessage[1] msgclass = _get_msg_class(code) msg = None remaining_data = rawmessage if msgclass is None: _LOGGER.debug('Did not find message class 0x%02x', rawmessage[1]) rawmessage = rawmessage[1:] rawmessage = _trim_buffer_garbage(rawmessage, False) if rawmessage: _LOGGER.debug('Create: %s', create) _LOGGER.debug('rawmessage: %s', binascii.hexlify(rawmessage)) msg, remaining_data = create(rawmessage) else: remaining_data = rawmessage else: if iscomplete(rawmessage): msg = msgclass.from_raw_message(rawmessage) if msg: remaining_data = rawmessage[len(msg.bytes):] # _LOGGER.debug("Returning msg: %s", msg) # _LOGGER.debug('Returning buffer: %s', binascii.hexlify(remaining_data)) return (msg, remaining_data)
python
def create(rawmessage): """Return an INSTEON message class based on a raw byte stream.""" rawmessage = _trim_buffer_garbage(rawmessage) if len(rawmessage) < 2: return (None, rawmessage) code = rawmessage[1] msgclass = _get_msg_class(code) msg = None remaining_data = rawmessage if msgclass is None: _LOGGER.debug('Did not find message class 0x%02x', rawmessage[1]) rawmessage = rawmessage[1:] rawmessage = _trim_buffer_garbage(rawmessage, False) if rawmessage: _LOGGER.debug('Create: %s', create) _LOGGER.debug('rawmessage: %s', binascii.hexlify(rawmessage)) msg, remaining_data = create(rawmessage) else: remaining_data = rawmessage else: if iscomplete(rawmessage): msg = msgclass.from_raw_message(rawmessage) if msg: remaining_data = rawmessage[len(msg.bytes):] # _LOGGER.debug("Returning msg: %s", msg) # _LOGGER.debug('Returning buffer: %s', binascii.hexlify(remaining_data)) return (msg, remaining_data)
[ "def", "create", "(", "rawmessage", ")", ":", "rawmessage", "=", "_trim_buffer_garbage", "(", "rawmessage", ")", "if", "len", "(", "rawmessage", ")", "<", "2", ":", "return", "(", "None", ",", "rawmessage", ")", "code", "=", "rawmessage", "[", "1", "]", ...
Return an INSTEON message class based on a raw byte stream.
[ "Return", "an", "INSTEON", "message", "class", "based", "on", "a", "raw", "byte", "stream", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/__init__.py#L56-L86
train
39,338
nugget/python-insteonplm
insteonplm/messages/__init__.py
iscomplete
def iscomplete(rawmessage): """Test if the raw message is a complete message.""" if len(rawmessage) < 2: return False if rawmessage[0] != 0x02: raise ValueError('message does not start with 0x02') messageBuffer = bytearray() filler = bytearray(30) messageBuffer.extend(rawmessage) messageBuffer.extend(filler) msg = _get_msg_class(rawmessage[1]) if hasattr(msg, 'receivedSize') and msg.receivedSize: expectedSize = msg.receivedSize else: _LOGGER.error('Unable to find a receivedSize for code 0x%x', rawmessage[1]) return ValueError is_expected_size = False if len(rawmessage) >= expectedSize: is_expected_size = True return is_expected_size
python
def iscomplete(rawmessage): """Test if the raw message is a complete message.""" if len(rawmessage) < 2: return False if rawmessage[0] != 0x02: raise ValueError('message does not start with 0x02') messageBuffer = bytearray() filler = bytearray(30) messageBuffer.extend(rawmessage) messageBuffer.extend(filler) msg = _get_msg_class(rawmessage[1]) if hasattr(msg, 'receivedSize') and msg.receivedSize: expectedSize = msg.receivedSize else: _LOGGER.error('Unable to find a receivedSize for code 0x%x', rawmessage[1]) return ValueError is_expected_size = False if len(rawmessage) >= expectedSize: is_expected_size = True return is_expected_size
[ "def", "iscomplete", "(", "rawmessage", ")", ":", "if", "len", "(", "rawmessage", ")", "<", "2", ":", "return", "False", "if", "rawmessage", "[", "0", "]", "!=", "0x02", ":", "raise", "ValueError", "(", "'message does not start with 0x02'", ")", "messageBuff...
Test if the raw message is a complete message.
[ "Test", "if", "the", "raw", "message", "is", "a", "complete", "message", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/__init__.py#L89-L115
train
39,339
nugget/python-insteonplm
insteonplm/messages/__init__.py
_get_msg_class
def _get_msg_class(code): """Get the message class based on the message code.""" msg_classes = {} msg_classes = _add_msg_class(msg_classes, MESSAGE_STANDARD_MESSAGE_RECEIVED_0X50, StandardReceive) msg_classes = _add_msg_class(msg_classes, MESSAGE_EXTENDED_MESSAGE_RECEIVED_0X51, ExtendedReceive) msg_classes = _add_msg_class(msg_classes, MESSAGE_X10_MESSAGE_RECEIVED_0X52, X10Received) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINKING_COMPLETED_0X53, AllLinkComplete) msg_classes = _add_msg_class(msg_classes, MESSAGE_BUTTON_EVENT_REPORT_0X54, ButtonEventReport) msg_classes = _add_msg_class(msg_classes, MESSAGE_USER_RESET_DETECTED_0X55, UserReset) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINK_CEANUP_FAILURE_REPORT_0X56, AllLinkCleanupFailureReport) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINK_RECORD_RESPONSE_0X57, AllLinkRecordResponse) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINK_CLEANUP_STATUS_REPORT_0X58, AllLinkCleanupStatusReport) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_IM_INFO_0X60, GetImInfo) msg_classes = _add_msg_class(msg_classes, MESSAGE_SEND_ALL_LINK_COMMAND_0X61, SendAllLinkCommand) msg_classes = _add_msg_class(msg_classes, MESSAGE_SEND_STANDARD_MESSAGE_0X62, StandardSend) msg_classes = _add_msg_class(msg_classes, MESSAGE_X10_MESSAGE_SEND_0X63, X10Send) msg_classes = _add_msg_class(msg_classes, MESSAGE_START_ALL_LINKING_0X64, StartAllLinking) msg_classes = _add_msg_class(msg_classes, MESSAGE_CANCEL_ALL_LINKING_0X65, CancelAllLinking) msg_classes = _add_msg_class(msg_classes, MESSAGE_RESET_IM_0X67, ResetIM) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_FIRST_ALL_LINK_RECORD_0X69, GetFirstAllLinkRecord) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_NEXT_ALL_LINK_RECORD_0X6A, GetNextAllLinkRecord) msg_classes = _add_msg_class(msg_classes, MESSAGE_MANAGE_ALL_LINK_RECORD_0X6F, ManageAllLinkRecord) msg_classes = _add_msg_class(msg_classes, MESSAGE_SET_IM_CONFIGURATION_0X6B, SetIMConfiguration) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_IM_CONFIGURATION_0X73, GetImConfiguration) return msg_classes.get(code, None)
python
def _get_msg_class(code): """Get the message class based on the message code.""" msg_classes = {} msg_classes = _add_msg_class(msg_classes, MESSAGE_STANDARD_MESSAGE_RECEIVED_0X50, StandardReceive) msg_classes = _add_msg_class(msg_classes, MESSAGE_EXTENDED_MESSAGE_RECEIVED_0X51, ExtendedReceive) msg_classes = _add_msg_class(msg_classes, MESSAGE_X10_MESSAGE_RECEIVED_0X52, X10Received) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINKING_COMPLETED_0X53, AllLinkComplete) msg_classes = _add_msg_class(msg_classes, MESSAGE_BUTTON_EVENT_REPORT_0X54, ButtonEventReport) msg_classes = _add_msg_class(msg_classes, MESSAGE_USER_RESET_DETECTED_0X55, UserReset) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINK_CEANUP_FAILURE_REPORT_0X56, AllLinkCleanupFailureReport) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINK_RECORD_RESPONSE_0X57, AllLinkRecordResponse) msg_classes = _add_msg_class(msg_classes, MESSAGE_ALL_LINK_CLEANUP_STATUS_REPORT_0X58, AllLinkCleanupStatusReport) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_IM_INFO_0X60, GetImInfo) msg_classes = _add_msg_class(msg_classes, MESSAGE_SEND_ALL_LINK_COMMAND_0X61, SendAllLinkCommand) msg_classes = _add_msg_class(msg_classes, MESSAGE_SEND_STANDARD_MESSAGE_0X62, StandardSend) msg_classes = _add_msg_class(msg_classes, MESSAGE_X10_MESSAGE_SEND_0X63, X10Send) msg_classes = _add_msg_class(msg_classes, MESSAGE_START_ALL_LINKING_0X64, StartAllLinking) msg_classes = _add_msg_class(msg_classes, MESSAGE_CANCEL_ALL_LINKING_0X65, CancelAllLinking) msg_classes = _add_msg_class(msg_classes, MESSAGE_RESET_IM_0X67, ResetIM) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_FIRST_ALL_LINK_RECORD_0X69, GetFirstAllLinkRecord) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_NEXT_ALL_LINK_RECORD_0X6A, GetNextAllLinkRecord) msg_classes = _add_msg_class(msg_classes, MESSAGE_MANAGE_ALL_LINK_RECORD_0X6F, ManageAllLinkRecord) msg_classes = _add_msg_class(msg_classes, MESSAGE_SET_IM_CONFIGURATION_0X6B, SetIMConfiguration) msg_classes = _add_msg_class(msg_classes, MESSAGE_GET_IM_CONFIGURATION_0X73, GetImConfiguration) return msg_classes.get(code, None)
[ "def", "_get_msg_class", "(", "code", ")", ":", "msg_classes", "=", "{", "}", "msg_classes", "=", "_add_msg_class", "(", "msg_classes", ",", "MESSAGE_STANDARD_MESSAGE_RECEIVED_0X50", ",", "StandardReceive", ")", "msg_classes", "=", "_add_msg_class", "(", "msg_classes"...
Get the message class based on the message code.
[ "Get", "the", "message", "class", "based", "on", "the", "message", "code", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/__init__.py#L118-L185
train
39,340
nugget/python-insteonplm
insteonplm/messages/__init__.py
_trim_buffer_garbage
def _trim_buffer_garbage(rawmessage, debug=True): """Remove leading bytes from a byte stream. A proper message byte stream begins with 0x02. """ while rawmessage and rawmessage[0] != MESSAGE_START_CODE_0X02: if debug: _LOGGER.debug('Buffer content: %s', binascii.hexlify(rawmessage)) _LOGGER.debug('Trimming leading buffer garbage') rawmessage = rawmessage[1:] return rawmessage
python
def _trim_buffer_garbage(rawmessage, debug=True): """Remove leading bytes from a byte stream. A proper message byte stream begins with 0x02. """ while rawmessage and rawmessage[0] != MESSAGE_START_CODE_0X02: if debug: _LOGGER.debug('Buffer content: %s', binascii.hexlify(rawmessage)) _LOGGER.debug('Trimming leading buffer garbage') rawmessage = rawmessage[1:] return rawmessage
[ "def", "_trim_buffer_garbage", "(", "rawmessage", ",", "debug", "=", "True", ")", ":", "while", "rawmessage", "and", "rawmessage", "[", "0", "]", "!=", "MESSAGE_START_CODE_0X02", ":", "if", "debug", ":", "_LOGGER", ".", "debug", "(", "'Buffer content: %s'", ",...
Remove leading bytes from a byte stream. A proper message byte stream begins with 0x02.
[ "Remove", "leading", "bytes", "from", "a", "byte", "stream", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/__init__.py#L193-L203
train
39,341
nugget/python-insteonplm
insteonplm/messages/messageFlags.py
MessageFlags.matches_pattern
def matches_pattern(self, other): """Test if current message match a patterns or template.""" if hasattr(other, 'messageType'): messageTypeIsEqual = False if self.messageType is None or other.messageType is None: messageTypeIsEqual = True else: messageTypeIsEqual = (self.messageType == other.messageType) extendedIsEqual = False if self.extended is None or other.extended is None: extendedIsEqual = True else: extendedIsEqual = (self.extended == other.extended) return messageTypeIsEqual and extendedIsEqual return False
python
def matches_pattern(self, other): """Test if current message match a patterns or template.""" if hasattr(other, 'messageType'): messageTypeIsEqual = False if self.messageType is None or other.messageType is None: messageTypeIsEqual = True else: messageTypeIsEqual = (self.messageType == other.messageType) extendedIsEqual = False if self.extended is None or other.extended is None: extendedIsEqual = True else: extendedIsEqual = (self.extended == other.extended) return messageTypeIsEqual and extendedIsEqual return False
[ "def", "matches_pattern", "(", "self", ",", "other", ")", ":", "if", "hasattr", "(", "other", ",", "'messageType'", ")", ":", "messageTypeIsEqual", "=", "False", "if", "self", ".", "messageType", "is", "None", "or", "other", ".", "messageType", "is", "None...
Test if current message match a patterns or template.
[ "Test", "if", "current", "message", "match", "a", "patterns", "or", "template", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/messageFlags.py#L52-L66
train
39,342
nugget/python-insteonplm
insteonplm/messages/messageFlags.py
MessageFlags.get_properties
def get_properties(cls): """Get all properties of the MessageFlags class.""" property_names = [p for p in dir(cls) if isinstance(getattr(cls, p), property)] return property_names
python
def get_properties(cls): """Get all properties of the MessageFlags class.""" property_names = [p for p in dir(cls) if isinstance(getattr(cls, p), property)] return property_names
[ "def", "get_properties", "(", "cls", ")", ":", "property_names", "=", "[", "p", "for", "p", "in", "dir", "(", "cls", ")", "if", "isinstance", "(", "getattr", "(", "cls", ",", "p", ")", ",", "property", ")", "]", "return", "property_names" ]
Get all properties of the MessageFlags class.
[ "Get", "all", "properties", "of", "the", "MessageFlags", "class", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/messageFlags.py#L69-L73
train
39,343
nugget/python-insteonplm
insteonplm/messages/messageFlags.py
MessageFlags.isDirect
def isDirect(self): """Test if the message is a direct message type.""" direct = (self._messageType == 0x00) if self.isDirectACK or self.isDirectNAK: direct = True return direct
python
def isDirect(self): """Test if the message is a direct message type.""" direct = (self._messageType == 0x00) if self.isDirectACK or self.isDirectNAK: direct = True return direct
[ "def", "isDirect", "(", "self", ")", ":", "direct", "=", "(", "self", ".", "_messageType", "==", "0x00", ")", "if", "self", ".", "isDirectACK", "or", "self", ".", "isDirectNAK", ":", "direct", "=", "True", "return", "direct" ]
Test if the message is a direct message type.
[ "Test", "if", "the", "message", "is", "a", "direct", "message", "type", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/messageFlags.py#L82-L87
train
39,344
nugget/python-insteonplm
insteonplm/messages/messageFlags.py
MessageFlags.create
def create(cls, messageType, extended, hopsleft=3, hopsmax=3): """Create message flags. messageType: integter 0 to 7: MESSAGE_TYPE_DIRECT_MESSAGE = 0 MESSAGE_TYPE_DIRECT_MESSAGE_ACK = 1 MESSAGE_TYPE_ALL_LINK_CLEANUP = 2 MESSAGE_TYPE_ALL_LINK_CLEANUP_ACK = 3 MESSAGE_TYPE_BROADCAST_MESSAGE = 4 MESSAGE_TYPE_DIRECT_MESSAGE_NAK = 5 MESSAGE_TYPE_ALL_LINK_BROADCAST = 6 MESSAGE_TYPE_ALL_LINK_CLEANUP_NAK = 7 extended: 1 for extended, 0 for standard hopsleft: int 0 - 3 hopsmax: int 0 - 3 """ flags = MessageFlags(None) if messageType < 8: flags._messageType = messageType else: flags._messageType = messageType >> 5 if extended in [0, 1, True, False]: if extended: flags._extended = 1 else: flags._extended = 0 else: flags._extended = extended >> 4 flags._hopsLeft = hopsleft flags._hopsMax = hopsmax return flags
python
def create(cls, messageType, extended, hopsleft=3, hopsmax=3): """Create message flags. messageType: integter 0 to 7: MESSAGE_TYPE_DIRECT_MESSAGE = 0 MESSAGE_TYPE_DIRECT_MESSAGE_ACK = 1 MESSAGE_TYPE_ALL_LINK_CLEANUP = 2 MESSAGE_TYPE_ALL_LINK_CLEANUP_ACK = 3 MESSAGE_TYPE_BROADCAST_MESSAGE = 4 MESSAGE_TYPE_DIRECT_MESSAGE_NAK = 5 MESSAGE_TYPE_ALL_LINK_BROADCAST = 6 MESSAGE_TYPE_ALL_LINK_CLEANUP_NAK = 7 extended: 1 for extended, 0 for standard hopsleft: int 0 - 3 hopsmax: int 0 - 3 """ flags = MessageFlags(None) if messageType < 8: flags._messageType = messageType else: flags._messageType = messageType >> 5 if extended in [0, 1, True, False]: if extended: flags._extended = 1 else: flags._extended = 0 else: flags._extended = extended >> 4 flags._hopsLeft = hopsleft flags._hopsMax = hopsmax return flags
[ "def", "create", "(", "cls", ",", "messageType", ",", "extended", ",", "hopsleft", "=", "3", ",", "hopsmax", "=", "3", ")", ":", "flags", "=", "MessageFlags", "(", "None", ")", "if", "messageType", "<", "8", ":", "flags", ".", "_messageType", "=", "m...
Create message flags. messageType: integter 0 to 7: MESSAGE_TYPE_DIRECT_MESSAGE = 0 MESSAGE_TYPE_DIRECT_MESSAGE_ACK = 1 MESSAGE_TYPE_ALL_LINK_CLEANUP = 2 MESSAGE_TYPE_ALL_LINK_CLEANUP_ACK = 3 MESSAGE_TYPE_BROADCAST_MESSAGE = 4 MESSAGE_TYPE_DIRECT_MESSAGE_NAK = 5 MESSAGE_TYPE_ALL_LINK_BROADCAST = 6 MESSAGE_TYPE_ALL_LINK_CLEANUP_NAK = 7 extended: 1 for extended, 0 for standard hopsleft: int 0 - 3 hopsmax: int 0 - 3
[ "Create", "message", "flags", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/messageFlags.py#L167-L197
train
39,345
nugget/python-insteonplm
insteonplm/messages/messageFlags.py
MessageFlags.bytes
def bytes(self): """Return a byte representation of the message flags.""" flagByte = 0x00 messageType = 0 if self._messageType is not None: messageType = self._messageType << 5 extendedBit = 0 if self._extended is None else self._extended << 4 hopsMax = 0 if self._hopsMax is None else self._hopsMax hopsLeft = 0 if self._hopsLeft is None else (self._hopsLeft << 2) flagByte = flagByte | messageType | extendedBit | hopsLeft | hopsMax return bytes([flagByte])
python
def bytes(self): """Return a byte representation of the message flags.""" flagByte = 0x00 messageType = 0 if self._messageType is not None: messageType = self._messageType << 5 extendedBit = 0 if self._extended is None else self._extended << 4 hopsMax = 0 if self._hopsMax is None else self._hopsMax hopsLeft = 0 if self._hopsLeft is None else (self._hopsLeft << 2) flagByte = flagByte | messageType | extendedBit | hopsLeft | hopsMax return bytes([flagByte])
[ "def", "bytes", "(", "self", ")", ":", "flagByte", "=", "0x00", "messageType", "=", "0", "if", "self", ".", "_messageType", "is", "not", "None", ":", "messageType", "=", "self", ".", "_messageType", "<<", "5", "extendedBit", "=", "0", "if", "self", "."...
Return a byte representation of the message flags.
[ "Return", "a", "byte", "representation", "of", "the", "message", "flags", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/messageFlags.py#L238-L248
train
39,346
nugget/python-insteonplm
insteonplm/messages/messageFlags.py
MessageFlags._normalize
def _normalize(self, flags): """Take any format of flags and turn it into a hex string.""" norm = None if isinstance(flags, MessageFlags): norm = flags.bytes elif isinstance(flags, bytearray): norm = binascii.hexlify(flags) elif isinstance(flags, int): norm = bytes([flags]) elif isinstance(flags, bytes): norm = binascii.hexlify(flags) elif isinstance(flags, str): flags = flags[0:2] norm = binascii.hexlify(binascii.unhexlify(flags.lower())) elif flags is None: norm = None else: _LOGGER.warning('MessageFlags with unknown type %s: %r', type(flags), flags) return norm
python
def _normalize(self, flags): """Take any format of flags and turn it into a hex string.""" norm = None if isinstance(flags, MessageFlags): norm = flags.bytes elif isinstance(flags, bytearray): norm = binascii.hexlify(flags) elif isinstance(flags, int): norm = bytes([flags]) elif isinstance(flags, bytes): norm = binascii.hexlify(flags) elif isinstance(flags, str): flags = flags[0:2] norm = binascii.hexlify(binascii.unhexlify(flags.lower())) elif flags is None: norm = None else: _LOGGER.warning('MessageFlags with unknown type %s: %r', type(flags), flags) return norm
[ "def", "_normalize", "(", "self", ",", "flags", ")", ":", "norm", "=", "None", "if", "isinstance", "(", "flags", ",", "MessageFlags", ")", ":", "norm", "=", "flags", ".", "bytes", "elif", "isinstance", "(", "flags", ",", "bytearray", ")", ":", "norm", ...
Take any format of flags and turn it into a hex string.
[ "Take", "any", "format", "of", "flags", "and", "turn", "it", "into", "a", "hex", "string", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/messageFlags.py#L256-L275
train
39,347
nugget/python-insteonplm
insteonplm/messages/messageFlags.py
MessageFlags._set_properties
def _set_properties(self, flags): """Set the properties of the message flags based on a byte input.""" flagByte = self._normalize(flags) if flagByte is not None: self._messageType = (flagByte[0] & 0xe0) >> 5 self._extended = (flagByte[0] & MESSAGE_FLAG_EXTENDED_0X10) >> 4 self._hopsLeft = (flagByte[0] & 0x0c) >> 2 self._hopsMax = flagByte[0] & 0x03 else: self._messageType = None self._extended = None self._hopsLeft = None self._hopsMax = None
python
def _set_properties(self, flags): """Set the properties of the message flags based on a byte input.""" flagByte = self._normalize(flags) if flagByte is not None: self._messageType = (flagByte[0] & 0xe0) >> 5 self._extended = (flagByte[0] & MESSAGE_FLAG_EXTENDED_0X10) >> 4 self._hopsLeft = (flagByte[0] & 0x0c) >> 2 self._hopsMax = flagByte[0] & 0x03 else: self._messageType = None self._extended = None self._hopsLeft = None self._hopsMax = None
[ "def", "_set_properties", "(", "self", ",", "flags", ")", ":", "flagByte", "=", "self", ".", "_normalize", "(", "flags", ")", "if", "flagByte", "is", "not", "None", ":", "self", ".", "_messageType", "=", "(", "flagByte", "[", "0", "]", "&", "0xe0", "...
Set the properties of the message flags based on a byte input.
[ "Set", "the", "properties", "of", "the", "message", "flags", "based", "on", "a", "byte", "input", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/messageFlags.py#L277-L290
train
39,348
nugget/python-insteonplm
insteonplm/states/sensor.py
LeakSensorDryWet.set_value
def set_value(self, dry_wet: LeakSensorState): """Set the value of the state to dry or wet.""" value = 0 if dry_wet == self._dry_wet_type: value = 1 self._update_subscribers(value)
python
def set_value(self, dry_wet: LeakSensorState): """Set the value of the state to dry or wet.""" value = 0 if dry_wet == self._dry_wet_type: value = 1 self._update_subscribers(value)
[ "def", "set_value", "(", "self", ",", "dry_wet", ":", "LeakSensorState", ")", ":", "value", "=", "0", "if", "dry_wet", "==", "self", ".", "_dry_wet_type", ":", "value", "=", "1", "self", ".", "_update_subscribers", "(", "value", ")" ]
Set the value of the state to dry or wet.
[ "Set", "the", "value", "of", "the", "state", "to", "dry", "or", "wet", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/sensor.py#L316-L321
train
39,349
nugget/python-insteonplm
insteonplm/states/sensor.py
LeakSensorDryWet._dry_wet_message_received
def _dry_wet_message_received(self, msg): """Report a dry or a wet state.""" for callback in self._dry_wet_callbacks: callback(self._dry_wet_type) self._update_subscribers(0x01)
python
def _dry_wet_message_received(self, msg): """Report a dry or a wet state.""" for callback in self._dry_wet_callbacks: callback(self._dry_wet_type) self._update_subscribers(0x01)
[ "def", "_dry_wet_message_received", "(", "self", ",", "msg", ")", ":", "for", "callback", "in", "self", ".", "_dry_wet_callbacks", ":", "callback", "(", "self", ".", "_dry_wet_type", ")", "self", ".", "_update_subscribers", "(", "0x01", ")" ]
Report a dry or a wet state.
[ "Report", "a", "dry", "or", "a", "wet", "state", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/sensor.py#L324-L328
train
39,350
nugget/python-insteonplm
insteonplm/states/sensor.py
LeakSensorHeartbeat.set_value
def set_value(self, dry_wet: LeakSensorState): """Set the state to wet or dry.""" if dry_wet == LeakSensorState.DRY: self._update_subscribers(0x11) else: self._update_subscribers(0x13)
python
def set_value(self, dry_wet: LeakSensorState): """Set the state to wet or dry.""" if dry_wet == LeakSensorState.DRY: self._update_subscribers(0x11) else: self._update_subscribers(0x13)
[ "def", "set_value", "(", "self", ",", "dry_wet", ":", "LeakSensorState", ")", ":", "if", "dry_wet", "==", "LeakSensorState", ".", "DRY", ":", "self", ".", "_update_subscribers", "(", "0x11", ")", "else", ":", "self", ".", "_update_subscribers", "(", "0x13", ...
Set the state to wet or dry.
[ "Set", "the", "state", "to", "wet", "or", "dry", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/sensor.py#L408-L413
train
39,351
nugget/python-insteonplm
insteonplm/states/sensor.py
LeakSensorHeartbeat._dry_message_received
def _dry_message_received(self, msg): """Report a dry state.""" for callback in self._dry_wet_callbacks: callback(LeakSensorState.DRY) self._update_subscribers(0x11)
python
def _dry_message_received(self, msg): """Report a dry state.""" for callback in self._dry_wet_callbacks: callback(LeakSensorState.DRY) self._update_subscribers(0x11)
[ "def", "_dry_message_received", "(", "self", ",", "msg", ")", ":", "for", "callback", "in", "self", ".", "_dry_wet_callbacks", ":", "callback", "(", "LeakSensorState", ".", "DRY", ")", "self", ".", "_update_subscribers", "(", "0x11", ")" ]
Report a dry state.
[ "Report", "a", "dry", "state", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/sensor.py#L416-L420
train
39,352
nugget/python-insteonplm
insteonplm/states/sensor.py
LeakSensorHeartbeat._wet_message_received
def _wet_message_received(self, msg): """Report a wet state.""" for callback in self._dry_wet_callbacks: callback(LeakSensorState.WET) self._update_subscribers(0x13)
python
def _wet_message_received(self, msg): """Report a wet state.""" for callback in self._dry_wet_callbacks: callback(LeakSensorState.WET) self._update_subscribers(0x13)
[ "def", "_wet_message_received", "(", "self", ",", "msg", ")", ":", "for", "callback", "in", "self", ".", "_dry_wet_callbacks", ":", "callback", "(", "LeakSensorState", ".", "WET", ")", "self", ".", "_update_subscribers", "(", "0x13", ")" ]
Report a wet state.
[ "Report", "a", "wet", "state", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/states/sensor.py#L423-L427
train
39,353
nugget/python-insteonplm
insteonplm/messagecallback.py
MessageCallback.add
def add(self, msg, callback, override=False): """Add a callback to the callback list. msg: Message template. callback: Callback method override: True - replace all existing callbacks for that template False - append the list of callbacks for that message Default is False """ if override: if isinstance(callback, list): self._dict[msg] = callback else: self._dict[msg] = [callback] else: cb = self[msg] cb.append(callback) self._dict[msg] = cb
python
def add(self, msg, callback, override=False): """Add a callback to the callback list. msg: Message template. callback: Callback method override: True - replace all existing callbacks for that template False - append the list of callbacks for that message Default is False """ if override: if isinstance(callback, list): self._dict[msg] = callback else: self._dict[msg] = [callback] else: cb = self[msg] cb.append(callback) self._dict[msg] = cb
[ "def", "add", "(", "self", ",", "msg", ",", "callback", ",", "override", "=", "False", ")", ":", "if", "override", ":", "if", "isinstance", "(", "callback", ",", "list", ")", ":", "self", ".", "_dict", "[", "msg", "]", "=", "callback", "else", ":",...
Add a callback to the callback list. msg: Message template. callback: Callback method override: True - replace all existing callbacks for that template False - append the list of callbacks for that message Default is False
[ "Add", "a", "callback", "to", "the", "callback", "list", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messagecallback.py#L64-L81
train
39,354
nugget/python-insteonplm
insteonplm/messagecallback.py
MessageCallback.remove
def remove(self, msg, callback): """Remove a callback from the callback list. msg: Message template callback: Callback method to remove. If callback is None, all callbacks for the message template are removed. """ if callback is None: self._dict.pop(msg, None) else: cb = self._dict.get(msg, []) try: cb.remove(callback) except ValueError: pass if cb: _LOGGER.debug('%d callbacks for message: %s', len(cb), msg) self.add(msg, cb, True) else: self._dict.pop(msg, None) _LOGGER.debug('Removed all callbacks for message: %s', msg)
python
def remove(self, msg, callback): """Remove a callback from the callback list. msg: Message template callback: Callback method to remove. If callback is None, all callbacks for the message template are removed. """ if callback is None: self._dict.pop(msg, None) else: cb = self._dict.get(msg, []) try: cb.remove(callback) except ValueError: pass if cb: _LOGGER.debug('%d callbacks for message: %s', len(cb), msg) self.add(msg, cb, True) else: self._dict.pop(msg, None) _LOGGER.debug('Removed all callbacks for message: %s', msg)
[ "def", "remove", "(", "self", ",", "msg", ",", "callback", ")", ":", "if", "callback", "is", "None", ":", "self", ".", "_dict", ".", "pop", "(", "msg", ",", "None", ")", "else", ":", "cb", "=", "self", ".", "_dict", ".", "get", "(", "msg", ",",...
Remove a callback from the callback list. msg: Message template callback: Callback method to remove. If callback is None, all callbacks for the message template are removed.
[ "Remove", "a", "callback", "from", "the", "callback", "list", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messagecallback.py#L83-L105
train
39,355
nugget/python-insteonplm
insteonplm/messagecallback.py
MessageCallback.get_callbacks_from_message
def get_callbacks_from_message(self, msg): """Return the callbacks associated with a message template.""" callbacks = [] for key in self._find_matching_keys(msg): for callback in self[key]: callbacks.append(callback) return callbacks
python
def get_callbacks_from_message(self, msg): """Return the callbacks associated with a message template.""" callbacks = [] for key in self._find_matching_keys(msg): for callback in self[key]: callbacks.append(callback) return callbacks
[ "def", "get_callbacks_from_message", "(", "self", ",", "msg", ")", ":", "callbacks", "=", "[", "]", "for", "key", "in", "self", ".", "_find_matching_keys", "(", "msg", ")", ":", "for", "callback", "in", "self", "[", "key", "]", ":", "callbacks", ".", "...
Return the callbacks associated with a message template.
[ "Return", "the", "callbacks", "associated", "with", "a", "message", "template", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messagecallback.py#L107-L113
train
39,356
nugget/python-insteonplm
insteonplm/devices/ipdb.py
IPDB.x10
def x10(self, feature): """Return an X10 device based on a feature. Current features: - OnOff - Dimmable """ x10_product = None for product in self._x10_products: if feature.lower() == product.feature: x10_product = product if not x10_product: x10_product = X10Product(feature, None) return x10_product
python
def x10(self, feature): """Return an X10 device based on a feature. Current features: - OnOff - Dimmable """ x10_product = None for product in self._x10_products: if feature.lower() == product.feature: x10_product = product if not x10_product: x10_product = X10Product(feature, None) return x10_product
[ "def", "x10", "(", "self", ",", "feature", ")", ":", "x10_product", "=", "None", "for", "product", "in", "self", ".", "_x10_products", ":", "if", "feature", ".", "lower", "(", ")", "==", "product", ".", "feature", ":", "x10_product", "=", "product", "i...
Return an X10 device based on a feature. Current features: - OnOff - Dimmable
[ "Return", "an", "X10", "device", "based", "on", "a", "feature", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/devices/ipdb.py#L386-L401
train
39,357
nugget/python-insteonplm
insteonplm/tools.py
interactive
def interactive(): """Create an interactive command line tool. Wrapper for an interactive session for manual commands to be entered. """ parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--device', default='/dev/ttyUSB0', help='Path to PLM device') parser.add_argument('-v', '--verbose', action='count', help='Set logging level to verbose') parser.add_argument('-l', '--logfile', default='', help='Log file name') parser.add_argument('--workdir', default='', help='Working directory for reading and saving ' 'device information.') args = parser.parse_args() loop = asyncio.get_event_loop() cmd = Commander(loop, args) cmd.start() try: loop.run_forever() except KeyboardInterrupt: if cmd.tools.plm: if cmd.tools.plm.transport: # _LOGGING.info('Closing the session') cmd.tools.plm.transport.close() loop.stop() pending = asyncio.Task.all_tasks(loop=loop) for task in pending: task.cancel() try: loop.run_until_complete(task) except asyncio.CancelledError: pass except KeyboardInterrupt: pass loop.close()
python
def interactive(): """Create an interactive command line tool. Wrapper for an interactive session for manual commands to be entered. """ parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--device', default='/dev/ttyUSB0', help='Path to PLM device') parser.add_argument('-v', '--verbose', action='count', help='Set logging level to verbose') parser.add_argument('-l', '--logfile', default='', help='Log file name') parser.add_argument('--workdir', default='', help='Working directory for reading and saving ' 'device information.') args = parser.parse_args() loop = asyncio.get_event_loop() cmd = Commander(loop, args) cmd.start() try: loop.run_forever() except KeyboardInterrupt: if cmd.tools.plm: if cmd.tools.plm.transport: # _LOGGING.info('Closing the session') cmd.tools.plm.transport.close() loop.stop() pending = asyncio.Task.all_tasks(loop=loop) for task in pending: task.cancel() try: loop.run_until_complete(task) except asyncio.CancelledError: pass except KeyboardInterrupt: pass loop.close()
[ "def", "interactive", "(", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "__doc__", ")", "parser", ".", "add_argument", "(", "'--device'", ",", "default", "=", "'/dev/ttyUSB0'", ",", "help", "=", "'Path to PLM device'", "...
Create an interactive command line tool. Wrapper for an interactive session for manual commands to be entered.
[ "Create", "an", "interactive", "command", "line", "tool", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L1203-L1240
train
39,358
nugget/python-insteonplm
insteonplm/tools.py
Tools.connect
async def connect(self, poll_devices=False, device=None, workdir=None): """Connect to the IM.""" await self.aldb_load_lock.acquire() device = self.host if self.host else self.device _LOGGING.info('Connecting to Insteon Modem at %s', device) self.device = device if device else self.device self.workdir = workdir if workdir else self.workdir conn = await insteonplm.Connection.create( device=self.device, host=self.host, port=self.port, username=self.username, password=self.password, loop=self.loop, poll_devices=poll_devices, workdir=self.workdir) _LOGGING.info('Connecton made to Insteon Modem at %s', device) conn.protocol.add_device_callback(self.async_new_device_callback) conn.protocol.add_all_link_done_callback( self.async_aldb_loaded_callback) self.plm = conn.protocol await self.aldb_load_lock if self.aldb_load_lock.locked(): self.aldb_load_lock.release()
python
async def connect(self, poll_devices=False, device=None, workdir=None): """Connect to the IM.""" await self.aldb_load_lock.acquire() device = self.host if self.host else self.device _LOGGING.info('Connecting to Insteon Modem at %s', device) self.device = device if device else self.device self.workdir = workdir if workdir else self.workdir conn = await insteonplm.Connection.create( device=self.device, host=self.host, port=self.port, username=self.username, password=self.password, loop=self.loop, poll_devices=poll_devices, workdir=self.workdir) _LOGGING.info('Connecton made to Insteon Modem at %s', device) conn.protocol.add_device_callback(self.async_new_device_callback) conn.protocol.add_all_link_done_callback( self.async_aldb_loaded_callback) self.plm = conn.protocol await self.aldb_load_lock if self.aldb_load_lock.locked(): self.aldb_load_lock.release()
[ "async", "def", "connect", "(", "self", ",", "poll_devices", "=", "False", ",", "device", "=", "None", ",", "workdir", "=", "None", ")", ":", "await", "self", ".", "aldb_load_lock", ".", "acquire", "(", ")", "device", "=", "self", ".", "host", "if", ...
Connect to the IM.
[ "Connect", "to", "the", "IM", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L79-L102
train
39,359
nugget/python-insteonplm
insteonplm/tools.py
Tools.monitor_mode
async def monitor_mode(self, poll_devices=False, device=None, workdir=None): """Place the IM in monitoring mode.""" print("Running monitor mode") await self.connect(poll_devices, device, workdir) self.plm.monitor_mode()
python
async def monitor_mode(self, poll_devices=False, device=None, workdir=None): """Place the IM in monitoring mode.""" print("Running monitor mode") await self.connect(poll_devices, device, workdir) self.plm.monitor_mode()
[ "async", "def", "monitor_mode", "(", "self", ",", "poll_devices", "=", "False", ",", "device", "=", "None", ",", "workdir", "=", "None", ")", ":", "print", "(", "\"Running monitor mode\"", ")", "await", "self", ".", "connect", "(", "poll_devices", ",", "de...
Place the IM in monitoring mode.
[ "Place", "the", "IM", "in", "monitoring", "mode", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L104-L109
train
39,360
nugget/python-insteonplm
insteonplm/tools.py
Tools.async_new_device_callback
def async_new_device_callback(self, device): """Log that our new device callback worked.""" _LOGGING.info( 'New Device: %s cat: 0x%02x subcat: 0x%02x desc: %s, model: %s', device.id, device.cat, device.subcat, device.description, device.model) for state in device.states: device.states[state].register_updates( self.async_state_change_callback)
python
def async_new_device_callback(self, device): """Log that our new device callback worked.""" _LOGGING.info( 'New Device: %s cat: 0x%02x subcat: 0x%02x desc: %s, model: %s', device.id, device.cat, device.subcat, device.description, device.model) for state in device.states: device.states[state].register_updates( self.async_state_change_callback)
[ "def", "async_new_device_callback", "(", "self", ",", "device", ")", ":", "_LOGGING", ".", "info", "(", "'New Device: %s cat: 0x%02x subcat: 0x%02x desc: %s, model: %s'", ",", "device", ".", "id", ",", "device", ".", "cat", ",", "device", ".", "subcat", ",", "devi...
Log that our new device callback worked.
[ "Log", "that", "our", "new", "device", "callback", "worked", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L111-L119
train
39,361
nugget/python-insteonplm
insteonplm/tools.py
Tools.async_state_change_callback
def async_state_change_callback(self, addr, state, value): """Log the state change.""" _LOGGING.info('Device %s state %s value is changed to %s', addr, state, value)
python
def async_state_change_callback(self, addr, state, value): """Log the state change.""" _LOGGING.info('Device %s state %s value is changed to %s', addr, state, value)
[ "def", "async_state_change_callback", "(", "self", ",", "addr", ",", "state", ",", "value", ")", ":", "_LOGGING", ".", "info", "(", "'Device %s state %s value is changed to %s'", ",", "addr", ",", "state", ",", "value", ")" ]
Log the state change.
[ "Log", "the", "state", "change", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L122-L125
train
39,362
nugget/python-insteonplm
insteonplm/tools.py
Tools.async_aldb_loaded_callback
def async_aldb_loaded_callback(self): """Unlock the ALDB load lock when loading is complete.""" if self.aldb_load_lock.locked(): self.aldb_load_lock.release() _LOGGING.info('ALDB Loaded')
python
def async_aldb_loaded_callback(self): """Unlock the ALDB load lock when loading is complete.""" if self.aldb_load_lock.locked(): self.aldb_load_lock.release() _LOGGING.info('ALDB Loaded')
[ "def", "async_aldb_loaded_callback", "(", "self", ")", ":", "if", "self", ".", "aldb_load_lock", ".", "locked", "(", ")", ":", "self", ".", "aldb_load_lock", ".", "release", "(", ")", "_LOGGING", ".", "info", "(", "'ALDB Loaded'", ")" ]
Unlock the ALDB load lock when loading is complete.
[ "Unlock", "the", "ALDB", "load", "lock", "when", "loading", "is", "complete", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L127-L131
train
39,363
nugget/python-insteonplm
insteonplm/tools.py
Tools.start_all_linking
async def start_all_linking(self, linkcode, group, address=None): """Start the All-Linking process with the IM and device.""" _LOGGING.info('Starting the All-Linking process') if address: linkdevice = self.plm.devices[Address(address).id] if not linkdevice: linkdevice = create(self.plm, address, None, None) _LOGGING.info('Attempting to link the PLM to device %s. ', address) self.plm.start_all_linking(linkcode, group) asyncio.sleep(.5, loop=self.loop) linkdevice.enter_linking_mode(group=group) else: _LOGGING.info('Starting All-Linking on PLM. ' 'Waiting for button press') self.plm.start_all_linking(linkcode, group) await asyncio.sleep(self.wait_time, loop=self.loop) _LOGGING.info('%d devices added to the All-Link Database', len(self.plm.devices)) await asyncio.sleep(.1, loop=self.loop)
python
async def start_all_linking(self, linkcode, group, address=None): """Start the All-Linking process with the IM and device.""" _LOGGING.info('Starting the All-Linking process') if address: linkdevice = self.plm.devices[Address(address).id] if not linkdevice: linkdevice = create(self.plm, address, None, None) _LOGGING.info('Attempting to link the PLM to device %s. ', address) self.plm.start_all_linking(linkcode, group) asyncio.sleep(.5, loop=self.loop) linkdevice.enter_linking_mode(group=group) else: _LOGGING.info('Starting All-Linking on PLM. ' 'Waiting for button press') self.plm.start_all_linking(linkcode, group) await asyncio.sleep(self.wait_time, loop=self.loop) _LOGGING.info('%d devices added to the All-Link Database', len(self.plm.devices)) await asyncio.sleep(.1, loop=self.loop)
[ "async", "def", "start_all_linking", "(", "self", ",", "linkcode", ",", "group", ",", "address", "=", "None", ")", ":", "_LOGGING", ".", "info", "(", "'Starting the All-Linking process'", ")", "if", "address", ":", "linkdevice", "=", "self", ".", "plm", ".",...
Start the All-Linking process with the IM and device.
[ "Start", "the", "All", "-", "Linking", "process", "with", "the", "IM", "and", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L133-L153
train
39,364
nugget/python-insteonplm
insteonplm/tools.py
Tools.list_devices
def list_devices(self): """List devices in the ALDB.""" if self.plm.devices: for addr in self.plm.devices: device = self.plm.devices[addr] if device.address.is_x10: _LOGGING.info('Device: %s %s', device.address.human, device.description) else: _LOGGING.info('Device: %s cat: 0x%02x subcat: 0x%02x ' 'desc: %s, model: %s', device.address.human, device.cat, device.subcat, device.description, device.model) else: _LOGGING.info('No devices found') if not self.plm.transport: _LOGGING.info('IM connection has not been made.') _LOGGING.info('Use `connect [device]` to open the connection')
python
def list_devices(self): """List devices in the ALDB.""" if self.plm.devices: for addr in self.plm.devices: device = self.plm.devices[addr] if device.address.is_x10: _LOGGING.info('Device: %s %s', device.address.human, device.description) else: _LOGGING.info('Device: %s cat: 0x%02x subcat: 0x%02x ' 'desc: %s, model: %s', device.address.human, device.cat, device.subcat, device.description, device.model) else: _LOGGING.info('No devices found') if not self.plm.transport: _LOGGING.info('IM connection has not been made.') _LOGGING.info('Use `connect [device]` to open the connection')
[ "def", "list_devices", "(", "self", ")", ":", "if", "self", ".", "plm", ".", "devices", ":", "for", "addr", "in", "self", ".", "plm", ".", "devices", ":", "device", "=", "self", ".", "plm", ".", "devices", "[", "addr", "]", "if", "device", ".", "...
List devices in the ALDB.
[ "List", "devices", "in", "the", "ALDB", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L155-L173
train
39,365
nugget/python-insteonplm
insteonplm/tools.py
Tools.print_device_aldb
def print_device_aldb(self, addr): """Diplay the All-Link database for a device.""" if Address(addr).id == self.plm.address.id: device = self.plm else: dev_addr = Address(addr) device = self.plm.devices[dev_addr.id] if device: if device.aldb.status in [ALDBStatus.LOADED, ALDBStatus.PARTIAL]: if device.aldb.status == ALDBStatus.PARTIAL: _LOGGING.info('ALDB partially loaded for device %s', addr) for mem_addr in device.aldb: record = device.aldb[mem_addr] _LOGGING.debug('mem_addr: %s', mem_addr) _LOGGING.info('ALDB record: %s', record) else: _LOGGING.info('ALDB not loaded. ' 'Use `load_aldb %s` first.', device.address.id) else: _LOGGING.info('Device not found.')
python
def print_device_aldb(self, addr): """Diplay the All-Link database for a device.""" if Address(addr).id == self.plm.address.id: device = self.plm else: dev_addr = Address(addr) device = self.plm.devices[dev_addr.id] if device: if device.aldb.status in [ALDBStatus.LOADED, ALDBStatus.PARTIAL]: if device.aldb.status == ALDBStatus.PARTIAL: _LOGGING.info('ALDB partially loaded for device %s', addr) for mem_addr in device.aldb: record = device.aldb[mem_addr] _LOGGING.debug('mem_addr: %s', mem_addr) _LOGGING.info('ALDB record: %s', record) else: _LOGGING.info('ALDB not loaded. ' 'Use `load_aldb %s` first.', device.address.id) else: _LOGGING.info('Device not found.')
[ "def", "print_device_aldb", "(", "self", ",", "addr", ")", ":", "if", "Address", "(", "addr", ")", ".", "id", "==", "self", ".", "plm", ".", "address", ".", "id", ":", "device", "=", "self", ".", "plm", "else", ":", "dev_addr", "=", "Address", "(",...
Diplay the All-Link database for a device.
[ "Diplay", "the", "All", "-", "Link", "database", "for", "a", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L221-L241
train
39,366
nugget/python-insteonplm
insteonplm/tools.py
Tools.print_all_aldb
def print_all_aldb(self): """Diplay the All-Link database for all devices.""" addr = self.plm.address.id _LOGGING.info('ALDB for PLM device %s', addr) self.print_device_aldb(addr) if self.plm.devices: for addr in self.plm.devices: _LOGGING.info('ALDB for device %s', addr) self.print_device_aldb(addr) else: _LOGGING.info('No devices found') if not self.plm.transport: _LOGGING.info('IM connection has not been made.') _LOGGING.info('Use `connect [device]` to open the connection')
python
def print_all_aldb(self): """Diplay the All-Link database for all devices.""" addr = self.plm.address.id _LOGGING.info('ALDB for PLM device %s', addr) self.print_device_aldb(addr) if self.plm.devices: for addr in self.plm.devices: _LOGGING.info('ALDB for device %s', addr) self.print_device_aldb(addr) else: _LOGGING.info('No devices found') if not self.plm.transport: _LOGGING.info('IM connection has not been made.') _LOGGING.info('Use `connect [device]` to open the connection')
[ "def", "print_all_aldb", "(", "self", ")", ":", "addr", "=", "self", ".", "plm", ".", "address", ".", "id", "_LOGGING", ".", "info", "(", "'ALDB for PLM device %s'", ",", "addr", ")", "self", ".", "print_device_aldb", "(", "addr", ")", "if", "self", ".",...
Diplay the All-Link database for all devices.
[ "Diplay", "the", "All", "-", "Link", "database", "for", "all", "devices", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L243-L256
train
39,367
nugget/python-insteonplm
insteonplm/tools.py
Tools.load_device_aldb
async def load_device_aldb(self, addr, clear=True): """Read the device ALDB.""" dev_addr = Address(addr) device = None if dev_addr == self.plm.address: device = self.plm else: device = self.plm.devices[dev_addr.id] if device: if clear: device.aldb.clear() device.read_aldb() await asyncio.sleep(1, loop=self.loop) while device.aldb.status == ALDBStatus.LOADING: await asyncio.sleep(1, loop=self.loop) if device.aldb.status == ALDBStatus.LOADED: _LOGGING.info('ALDB loaded for device %s', addr) self.print_device_aldb(addr) else: _LOGGING.error('Could not find device %s', addr)
python
async def load_device_aldb(self, addr, clear=True): """Read the device ALDB.""" dev_addr = Address(addr) device = None if dev_addr == self.plm.address: device = self.plm else: device = self.plm.devices[dev_addr.id] if device: if clear: device.aldb.clear() device.read_aldb() await asyncio.sleep(1, loop=self.loop) while device.aldb.status == ALDBStatus.LOADING: await asyncio.sleep(1, loop=self.loop) if device.aldb.status == ALDBStatus.LOADED: _LOGGING.info('ALDB loaded for device %s', addr) self.print_device_aldb(addr) else: _LOGGING.error('Could not find device %s', addr)
[ "async", "def", "load_device_aldb", "(", "self", ",", "addr", ",", "clear", "=", "True", ")", ":", "dev_addr", "=", "Address", "(", "addr", ")", "device", "=", "None", "if", "dev_addr", "==", "self", ".", "plm", ".", "address", ":", "device", "=", "s...
Read the device ALDB.
[ "Read", "the", "device", "ALDB", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L258-L277
train
39,368
nugget/python-insteonplm
insteonplm/tools.py
Tools.load_all_aldb
async def load_all_aldb(self, clear=True): """Read all devices ALDB.""" for addr in self.plm.devices: await self.load_device_aldb(addr, clear)
python
async def load_all_aldb(self, clear=True): """Read all devices ALDB.""" for addr in self.plm.devices: await self.load_device_aldb(addr, clear)
[ "async", "def", "load_all_aldb", "(", "self", ",", "clear", "=", "True", ")", ":", "for", "addr", "in", "self", ".", "plm", ".", "devices", ":", "await", "self", ".", "load_device_aldb", "(", "addr", ",", "clear", ")" ]
Read all devices ALDB.
[ "Read", "all", "devices", "ALDB", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L279-L282
train
39,369
nugget/python-insteonplm
insteonplm/tools.py
Tools.add_device_override
def add_device_override(self, addr, cat, subcat, firmware=None): """Add a device override to the PLM.""" self.plm.devices.add_override(addr, 'cat', cat) self.plm.devices.add_override(addr, 'subcat', subcat) if firmware: self.plm.devices.add_override(addr, 'firmware', firmware)
python
def add_device_override(self, addr, cat, subcat, firmware=None): """Add a device override to the PLM.""" self.plm.devices.add_override(addr, 'cat', cat) self.plm.devices.add_override(addr, 'subcat', subcat) if firmware: self.plm.devices.add_override(addr, 'firmware', firmware)
[ "def", "add_device_override", "(", "self", ",", "addr", ",", "cat", ",", "subcat", ",", "firmware", "=", "None", ")", ":", "self", ".", "plm", ".", "devices", ".", "add_override", "(", "addr", ",", "'cat'", ",", "cat", ")", "self", ".", "plm", ".", ...
Add a device override to the PLM.
[ "Add", "a", "device", "override", "to", "the", "PLM", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L311-L316
train
39,370
nugget/python-insteonplm
insteonplm/tools.py
Tools.add_x10_device
def add_x10_device(self, housecode, unitcode, dev_type): """Add an X10 device to the PLM.""" device = None try: device = self.plm.devices.add_x10_device(self.plm, housecode, unitcode, dev_type) except ValueError: pass return device
python
def add_x10_device(self, housecode, unitcode, dev_type): """Add an X10 device to the PLM.""" device = None try: device = self.plm.devices.add_x10_device(self.plm, housecode, unitcode, dev_type) except ValueError: pass return device
[ "def", "add_x10_device", "(", "self", ",", "housecode", ",", "unitcode", ",", "dev_type", ")", ":", "device", "=", "None", "try", ":", "device", "=", "self", ".", "plm", ".", "devices", ".", "add_x10_device", "(", "self", ".", "plm", ",", "housecode", ...
Add an X10 device to the PLM.
[ "Add", "an", "X10", "device", "to", "the", "PLM", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L318-L326
train
39,371
nugget/python-insteonplm
insteonplm/tools.py
Commander.start
def start(self): """Start the command process loop.""" self.loop.create_task(self._read_line()) self.loop.create_task(self._greeting())
python
def start(self): """Start the command process loop.""" self.loop.create_task(self._read_line()) self.loop.create_task(self._greeting())
[ "def", "start", "(", "self", ")", ":", "self", ".", "loop", ".", "create_task", "(", "self", ".", "_read_line", "(", ")", ")", "self", ".", "loop", ".", "create_task", "(", "self", ".", "_greeting", "(", ")", ")" ]
Start the command process loop.
[ "Start", "the", "command", "process", "loop", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L364-L367
train
39,372
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_connect
async def do_connect(self, args): """Connect to the PLM device. Usage: connect [device [workdir]] Arguments: device: PLM device (default /dev/ttyUSB0) workdir: Working directory to save and load device information """ params = args.split() device = '/dev/ttyUSB0' workdir = None try: device = params[0] except IndexError: if self.tools.device: device = self.tools.device try: workdir = params[1] except IndexError: if self.tools.workdir: workdir = self.tools.workdir if device: await self.tools.connect(False, device=device, workdir=workdir) _LOGGING.info('Connection complete.')
python
async def do_connect(self, args): """Connect to the PLM device. Usage: connect [device [workdir]] Arguments: device: PLM device (default /dev/ttyUSB0) workdir: Working directory to save and load device information """ params = args.split() device = '/dev/ttyUSB0' workdir = None try: device = params[0] except IndexError: if self.tools.device: device = self.tools.device try: workdir = params[1] except IndexError: if self.tools.workdir: workdir = self.tools.workdir if device: await self.tools.connect(False, device=device, workdir=workdir) _LOGGING.info('Connection complete.')
[ "async", "def", "do_connect", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "device", "=", "'/dev/ttyUSB0'", "workdir", "=", "None", "try", ":", "device", "=", "params", "[", "0", "]", "except", "IndexError", ":", ...
Connect to the PLM device. Usage: connect [device [workdir]] Arguments: device: PLM device (default /dev/ttyUSB0) workdir: Working directory to save and load device information
[ "Connect", "to", "the", "PLM", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L422-L448
train
39,373
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_running_tasks
def do_running_tasks(self, arg): """List tasks running in the background. Usage: running_tasks Arguments: """ for task in asyncio.Task.all_tasks(loop=self.loop): _LOGGING.info(task)
python
def do_running_tasks(self, arg): """List tasks running in the background. Usage: running_tasks Arguments: """ for task in asyncio.Task.all_tasks(loop=self.loop): _LOGGING.info(task)
[ "def", "do_running_tasks", "(", "self", ",", "arg", ")", ":", "for", "task", "in", "asyncio", ".", "Task", ".", "all_tasks", "(", "loop", "=", "self", ".", "loop", ")", ":", "_LOGGING", ".", "info", "(", "task", ")" ]
List tasks running in the background. Usage: running_tasks Arguments:
[ "List", "tasks", "running", "in", "the", "background", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L451-L459
train
39,374
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_add_all_link
def do_add_all_link(self, args): """Add an All-Link record to the IM and a device. Usage: add_all_link [linkcode] [group] [address] Arguments: linkcode: 0 - PLM is responder 1 - PLM is controller 3 - PLM is controller or responder Default 1 group: All-Link group number (0 - 255). Default 0. address: INSTEON device to link with (not supported by all devices) """ linkcode = 1 group = 0 addr = None params = args.split() if params: try: linkcode = int(params[0]) except IndexError: linkcode = 1 except ValueError: linkcode = None try: group = int(params[1]) except IndexError: group = 0 except ValueError: group = None try: addr = params[2] except IndexError: addr = None if linkcode in [0, 1, 3] and 255 >= group >= 0: self.loop.create_task( self.tools.start_all_linking(linkcode, group, addr)) else: _LOGGING.error('Link code %d or group number %d not valid', linkcode, group) self.do_help('add_all_link')
python
def do_add_all_link(self, args): """Add an All-Link record to the IM and a device. Usage: add_all_link [linkcode] [group] [address] Arguments: linkcode: 0 - PLM is responder 1 - PLM is controller 3 - PLM is controller or responder Default 1 group: All-Link group number (0 - 255). Default 0. address: INSTEON device to link with (not supported by all devices) """ linkcode = 1 group = 0 addr = None params = args.split() if params: try: linkcode = int(params[0]) except IndexError: linkcode = 1 except ValueError: linkcode = None try: group = int(params[1]) except IndexError: group = 0 except ValueError: group = None try: addr = params[2] except IndexError: addr = None if linkcode in [0, 1, 3] and 255 >= group >= 0: self.loop.create_task( self.tools.start_all_linking(linkcode, group, addr)) else: _LOGGING.error('Link code %d or group number %d not valid', linkcode, group) self.do_help('add_all_link')
[ "def", "do_add_all_link", "(", "self", ",", "args", ")", ":", "linkcode", "=", "1", "group", "=", "0", "addr", "=", "None", "params", "=", "args", ".", "split", "(", ")", "if", "params", ":", "try", ":", "linkcode", "=", "int", "(", "params", "[", ...
Add an All-Link record to the IM and a device. Usage: add_all_link [linkcode] [group] [address] Arguments: linkcode: 0 - PLM is responder 1 - PLM is controller 3 - PLM is controller or responder Default 1 group: All-Link group number (0 - 255). Default 0. address: INSTEON device to link with (not supported by all devices)
[ "Add", "an", "All", "-", "Link", "record", "to", "the", "IM", "and", "a", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L503-L546
train
39,375
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_print_aldb
def do_print_aldb(self, args): """Print the All-Link database for a device. Usage: print_aldb address|plm|all Arguments: address: INSTEON address of the device plm: Print the All-Link database for the PLM all: Print the All-Link database for all devices This method requires that the device ALDB has been loaded. To load the device ALDB use the command: load_aldb address|plm|all """ params = args.split() addr = None try: addr = params[0] except IndexError: _LOGGING.error('Device address required.') self.do_help('print_aldb') if addr: if addr.lower() == 'all': self.tools.print_all_aldb() elif addr.lower() == 'plm': addr = self.tools.plm.address.id self.tools.print_device_aldb(addr) else: self.tools.print_device_aldb(addr)
python
def do_print_aldb(self, args): """Print the All-Link database for a device. Usage: print_aldb address|plm|all Arguments: address: INSTEON address of the device plm: Print the All-Link database for the PLM all: Print the All-Link database for all devices This method requires that the device ALDB has been loaded. To load the device ALDB use the command: load_aldb address|plm|all """ params = args.split() addr = None try: addr = params[0] except IndexError: _LOGGING.error('Device address required.') self.do_help('print_aldb') if addr: if addr.lower() == 'all': self.tools.print_all_aldb() elif addr.lower() == 'plm': addr = self.tools.plm.address.id self.tools.print_device_aldb(addr) else: self.tools.print_device_aldb(addr)
[ "def", "do_print_aldb", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "addr", "=", "None", "try", ":", "addr", "=", "params", "[", "0", "]", "except", "IndexError", ":", "_LOGGING", ".", "error", "(", "'Device add...
Print the All-Link database for a device. Usage: print_aldb address|plm|all Arguments: address: INSTEON address of the device plm: Print the All-Link database for the PLM all: Print the All-Link database for all devices This method requires that the device ALDB has been loaded. To load the device ALDB use the command: load_aldb address|plm|all
[ "Print", "the", "All", "-", "Link", "database", "for", "a", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L581-L611
train
39,376
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_set_hub_connection
def do_set_hub_connection(self, args): """Set Hub connection parameters. Usage: set_hub_connection username password host [port] Arguments: username: Hub username password: Hub password host: host name or IP address port: IP port [default 25105] """ params = args.split() username = None password = None host = None port = None try: username = params[0] password = params[1] host = params[2] port = params[3] except IndexError: pass if username and password and host: if not port: port = 25105 self.tools.username = username self.tools.password = password self.tools.host = host self.tools.port = port else: _LOGGING.error('username password host are required') self.do_help('set_hub_connection')
python
def do_set_hub_connection(self, args): """Set Hub connection parameters. Usage: set_hub_connection username password host [port] Arguments: username: Hub username password: Hub password host: host name or IP address port: IP port [default 25105] """ params = args.split() username = None password = None host = None port = None try: username = params[0] password = params[1] host = params[2] port = params[3] except IndexError: pass if username and password and host: if not port: port = 25105 self.tools.username = username self.tools.password = password self.tools.host = host self.tools.port = port else: _LOGGING.error('username password host are required') self.do_help('set_hub_connection')
[ "def", "do_set_hub_connection", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "username", "=", "None", "password", "=", "None", "host", "=", "None", "port", "=", "None", "try", ":", "username", "=", "params", "[", ...
Set Hub connection parameters. Usage: set_hub_connection username password host [port] Arguments: username: Hub username password: Hub password host: host name or IP address port: IP port [default 25105]
[ "Set", "Hub", "connection", "parameters", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L613-L648
train
39,377
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_set_log_file
def do_set_log_file(self, args): """Set the log file. Usage: set_log_file filename Parameters: filename: log file name to write to THIS CAN ONLY BE CALLED ONCE AND MUST BE CALLED BEFORE ANY LOGGING STARTS. """ params = args.split() try: filename = params[0] logging.basicConfig(filename=filename) except IndexError: self.do_help('set_log_file')
python
def do_set_log_file(self, args): """Set the log file. Usage: set_log_file filename Parameters: filename: log file name to write to THIS CAN ONLY BE CALLED ONCE AND MUST BE CALLED BEFORE ANY LOGGING STARTS. """ params = args.split() try: filename = params[0] logging.basicConfig(filename=filename) except IndexError: self.do_help('set_log_file')
[ "def", "do_set_log_file", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "try", ":", "filename", "=", "params", "[", "0", "]", "logging", ".", "basicConfig", "(", "filename", "=", "filename", ")", "except", "IndexErr...
Set the log file. Usage: set_log_file filename Parameters: filename: log file name to write to THIS CAN ONLY BE CALLED ONCE AND MUST BE CALLED BEFORE ANY LOGGING STARTS.
[ "Set", "the", "log", "file", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L650-L666
train
39,378
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_load_aldb
async def do_load_aldb(self, args): """Load the All-Link database for a device. Usage: load_aldb address|all [clear_prior] Arguments: address: NSTEON address of the device all: Load the All-Link database for all devices clear_prior: y|n y - Clear the prior data and start fresh. n - Keep the prior data and only apply changes Default is y This does NOT write to the database so no changes are made to the device with this command. """ params = args.split() addr = None clear = True try: addr = params[0] except IndexError: _LOGGING.error('Device address required.') self.do_help('load_aldb') try: clear_prior = params[1] _LOGGING.info('param clear_prior %s', clear_prior) if clear_prior.lower() == 'y': clear = True elif clear_prior.lower() == 'n': clear = False else: _LOGGING.error('Invalid value for parameter `clear_prior`') _LOGGING.error('Valid values are `y` or `n`') except IndexError: pass if addr: if addr.lower() == 'all': await self.tools.load_all_aldb(clear) else: await self.tools.load_device_aldb(addr, clear) else: self.do_help('load_aldb')
python
async def do_load_aldb(self, args): """Load the All-Link database for a device. Usage: load_aldb address|all [clear_prior] Arguments: address: NSTEON address of the device all: Load the All-Link database for all devices clear_prior: y|n y - Clear the prior data and start fresh. n - Keep the prior data and only apply changes Default is y This does NOT write to the database so no changes are made to the device with this command. """ params = args.split() addr = None clear = True try: addr = params[0] except IndexError: _LOGGING.error('Device address required.') self.do_help('load_aldb') try: clear_prior = params[1] _LOGGING.info('param clear_prior %s', clear_prior) if clear_prior.lower() == 'y': clear = True elif clear_prior.lower() == 'n': clear = False else: _LOGGING.error('Invalid value for parameter `clear_prior`') _LOGGING.error('Valid values are `y` or `n`') except IndexError: pass if addr: if addr.lower() == 'all': await self.tools.load_all_aldb(clear) else: await self.tools.load_device_aldb(addr, clear) else: self.do_help('load_aldb')
[ "async", "def", "do_load_aldb", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "addr", "=", "None", "clear", "=", "True", "try", ":", "addr", "=", "params", "[", "0", "]", "except", "IndexError", ":", "_LOGGING", ...
Load the All-Link database for a device. Usage: load_aldb address|all [clear_prior] Arguments: address: NSTEON address of the device all: Load the All-Link database for all devices clear_prior: y|n y - Clear the prior data and start fresh. n - Keep the prior data and only apply changes Default is y This does NOT write to the database so no changes are made to the device with this command.
[ "Load", "the", "All", "-", "Link", "database", "for", "a", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L668-L712
train
39,379
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_write_aldb
async def do_write_aldb(self, args): """Write device All-Link record. WARNING THIS METHOD CAN DAMAGE YOUR DEVICE IF USED INCORRECTLY. Please ensure the memory id is appropriate for the device. You must load the ALDB of the device before using this method. The memory id must be an existing memory id in the ALDB or this method will return an error. If you are looking to create a new link between two devices, use the `link_devices` command or the `start_all_linking` command. Usage: write_aldb addr memory mode group target [data1 data2 data3] Required Parameters: addr: Inseon address of the device to write memory: record ID of the record to write (i.e. 0fff) mode: r | c r = Device is a responder of target c = Device is a controller of target group: All-Link group integer target: Insteon address of the link target device Optional Parameters: data1: int = Device sepcific data2: int = Device specific data3: int = Device specific """ params = args.split() addr = None mem_bytes = None memory = None mode = None group = None target = None data1 = 0x00 data2 = 0x00 data3 = 0x00 try: addr = Address(params[0]) mem_bytes = binascii.unhexlify(params[1]) memory = int.from_bytes(mem_bytes, byteorder='big') mode = params[2] group = int(params[3]) target = Address(params[4]) _LOGGING.info('address: %s', addr) _LOGGING.info('memory: %04x', memory) _LOGGING.info('mode: %s', mode) _LOGGING.info('group: %d', group) _LOGGING.info('target: %s', target) except IndexError: _LOGGING.error('Device address memory mode group and target ' 'are all required.') self.do_help('write_aldb') except ValueError: _LOGGING.error('Value error - Check parameters') self.do_help('write_aldb') try: data1 = int(params[5]) data2 = int(params[6]) data3 = int(params[7]) except IndexError: pass except ValueError: addr = None _LOGGING.error('Value error - Check parameters') self.do_help('write_aldb') return if addr and memory and mode and isinstance(group, int) and target: await self.tools.write_aldb(addr, memory, mode, group, target, data1, data2, data3)
python
async def do_write_aldb(self, args): """Write device All-Link record. WARNING THIS METHOD CAN DAMAGE YOUR DEVICE IF USED INCORRECTLY. Please ensure the memory id is appropriate for the device. You must load the ALDB of the device before using this method. The memory id must be an existing memory id in the ALDB or this method will return an error. If you are looking to create a new link between two devices, use the `link_devices` command or the `start_all_linking` command. Usage: write_aldb addr memory mode group target [data1 data2 data3] Required Parameters: addr: Inseon address of the device to write memory: record ID of the record to write (i.e. 0fff) mode: r | c r = Device is a responder of target c = Device is a controller of target group: All-Link group integer target: Insteon address of the link target device Optional Parameters: data1: int = Device sepcific data2: int = Device specific data3: int = Device specific """ params = args.split() addr = None mem_bytes = None memory = None mode = None group = None target = None data1 = 0x00 data2 = 0x00 data3 = 0x00 try: addr = Address(params[0]) mem_bytes = binascii.unhexlify(params[1]) memory = int.from_bytes(mem_bytes, byteorder='big') mode = params[2] group = int(params[3]) target = Address(params[4]) _LOGGING.info('address: %s', addr) _LOGGING.info('memory: %04x', memory) _LOGGING.info('mode: %s', mode) _LOGGING.info('group: %d', group) _LOGGING.info('target: %s', target) except IndexError: _LOGGING.error('Device address memory mode group and target ' 'are all required.') self.do_help('write_aldb') except ValueError: _LOGGING.error('Value error - Check parameters') self.do_help('write_aldb') try: data1 = int(params[5]) data2 = int(params[6]) data3 = int(params[7]) except IndexError: pass except ValueError: addr = None _LOGGING.error('Value error - Check parameters') self.do_help('write_aldb') return if addr and memory and mode and isinstance(group, int) and target: await self.tools.write_aldb(addr, memory, mode, group, target, data1, data2, data3)
[ "async", "def", "do_write_aldb", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "addr", "=", "None", "mem_bytes", "=", "None", "memory", "=", "None", "mode", "=", "None", "group", "=", "None", "target", "=", "None"...
Write device All-Link record. WARNING THIS METHOD CAN DAMAGE YOUR DEVICE IF USED INCORRECTLY. Please ensure the memory id is appropriate for the device. You must load the ALDB of the device before using this method. The memory id must be an existing memory id in the ALDB or this method will return an error. If you are looking to create a new link between two devices, use the `link_devices` command or the `start_all_linking` command. Usage: write_aldb addr memory mode group target [data1 data2 data3] Required Parameters: addr: Inseon address of the device to write memory: record ID of the record to write (i.e. 0fff) mode: r | c r = Device is a responder of target c = Device is a controller of target group: All-Link group integer target: Insteon address of the link target device Optional Parameters: data1: int = Device sepcific data2: int = Device specific data3: int = Device specific
[ "Write", "device", "All", "-", "Link", "record", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L714-L790
train
39,380
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_del_aldb
async def do_del_aldb(self, args): """Delete device All-Link record. WARNING THIS METHOD CAN DAMAGE YOUR DEVICE IF USED INCORRECTLY. Please ensure the memory id is appropriate for the device. You must load the ALDB of the device before using this method. The memory id must be an existing memory id in the ALDB or this method will return an error. If you are looking to create a new link between two devices, use the `link_devices` command or the `start_all_linking` command. Usage: del_aldb addr memory Required Parameters: addr: Inseon address of the device to write memory: record ID of the record to write (i.e. 0fff) """ params = args.split() addr = None mem_bytes = None memory = None try: addr = Address(params[0]) mem_bytes = binascii.unhexlify(params[1]) memory = int.from_bytes(mem_bytes, byteorder='big') _LOGGING.info('address: %s', addr) _LOGGING.info('memory: %04x', memory) except IndexError: _LOGGING.error('Device address and memory are required.') self.do_help('del_aldb') except ValueError: _LOGGING.error('Value error - Check parameters') self.do_help('write_aldb') if addr and memory: await self.tools.del_aldb(addr, memory)
python
async def do_del_aldb(self, args): """Delete device All-Link record. WARNING THIS METHOD CAN DAMAGE YOUR DEVICE IF USED INCORRECTLY. Please ensure the memory id is appropriate for the device. You must load the ALDB of the device before using this method. The memory id must be an existing memory id in the ALDB or this method will return an error. If you are looking to create a new link between two devices, use the `link_devices` command or the `start_all_linking` command. Usage: del_aldb addr memory Required Parameters: addr: Inseon address of the device to write memory: record ID of the record to write (i.e. 0fff) """ params = args.split() addr = None mem_bytes = None memory = None try: addr = Address(params[0]) mem_bytes = binascii.unhexlify(params[1]) memory = int.from_bytes(mem_bytes, byteorder='big') _LOGGING.info('address: %s', addr) _LOGGING.info('memory: %04x', memory) except IndexError: _LOGGING.error('Device address and memory are required.') self.do_help('del_aldb') except ValueError: _LOGGING.error('Value error - Check parameters') self.do_help('write_aldb') if addr and memory: await self.tools.del_aldb(addr, memory)
[ "async", "def", "do_del_aldb", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "addr", "=", "None", "mem_bytes", "=", "None", "memory", "=", "None", "try", ":", "addr", "=", "Address", "(", "params", "[", "0", "]"...
Delete device All-Link record. WARNING THIS METHOD CAN DAMAGE YOUR DEVICE IF USED INCORRECTLY. Please ensure the memory id is appropriate for the device. You must load the ALDB of the device before using this method. The memory id must be an existing memory id in the ALDB or this method will return an error. If you are looking to create a new link between two devices, use the `link_devices` command or the `start_all_linking` command. Usage: del_aldb addr memory Required Parameters: addr: Inseon address of the device to write memory: record ID of the record to write (i.e. 0fff)
[ "Delete", "device", "All", "-", "Link", "record", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L792-L832
train
39,381
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_set_log_level
def do_set_log_level(self, arg): """Set the log level. Usage: set_log_level i|v Parameters: log_level: i - info | v - verbose """ if arg in ['i', 'v']: _LOGGING.info('Setting log level to %s', arg) if arg == 'i': _LOGGING.setLevel(logging.INFO) _INSTEONPLM_LOGGING.setLevel(logging.INFO) else: _LOGGING.setLevel(logging.DEBUG) _INSTEONPLM_LOGGING.setLevel(logging.DEBUG) else: _LOGGING.error('Log level value error.') self.do_help('set_log_level')
python
def do_set_log_level(self, arg): """Set the log level. Usage: set_log_level i|v Parameters: log_level: i - info | v - verbose """ if arg in ['i', 'v']: _LOGGING.info('Setting log level to %s', arg) if arg == 'i': _LOGGING.setLevel(logging.INFO) _INSTEONPLM_LOGGING.setLevel(logging.INFO) else: _LOGGING.setLevel(logging.DEBUG) _INSTEONPLM_LOGGING.setLevel(logging.DEBUG) else: _LOGGING.error('Log level value error.') self.do_help('set_log_level')
[ "def", "do_set_log_level", "(", "self", ",", "arg", ")", ":", "if", "arg", "in", "[", "'i'", ",", "'v'", "]", ":", "_LOGGING", ".", "info", "(", "'Setting log level to %s'", ",", "arg", ")", "if", "arg", "==", "'i'", ":", "_LOGGING", ".", "setLevel", ...
Set the log level. Usage: set_log_level i|v Parameters: log_level: i - info | v - verbose
[ "Set", "the", "log", "level", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L834-L853
train
39,382
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_set_device
def do_set_device(self, args): """Set the PLM OS device. Device defaults to /dev/ttyUSB0 Usage: set_device device Arguments: device: Required - INSTEON PLM device """ params = args.split() device = None try: device = params[0] except IndexError: _LOGGING.error('Device name required.') self.do_help('set_device') if device: self.tools.device = device
python
def do_set_device(self, args): """Set the PLM OS device. Device defaults to /dev/ttyUSB0 Usage: set_device device Arguments: device: Required - INSTEON PLM device """ params = args.split() device = None try: device = params[0] except IndexError: _LOGGING.error('Device name required.') self.do_help('set_device') if device: self.tools.device = device
[ "def", "do_set_device", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "device", "=", "None", "try", ":", "device", "=", "params", "[", "0", "]", "except", "IndexError", ":", "_LOGGING", ".", "error", "(", "'Device...
Set the PLM OS device. Device defaults to /dev/ttyUSB0 Usage: set_device device Arguments: device: Required - INSTEON PLM device
[ "Set", "the", "PLM", "OS", "device", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L855-L875
train
39,383
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_set_workdir
def do_set_workdir(self, args): """Set the working directory. The working directory is used to load and save known devices to improve startup times. During startup the application loads and saves a file `insteon_plm_device_info.dat`. This file is saved in the working directory. The working directory has no default value. If the working directory is not set, the `insteon_plm_device_info.dat` file is not loaded or saved. Usage: set_workdir workdir Arguments: workdir: Required - Working directory to load and save devie list """ params = args.split() workdir = None try: workdir = params[0] except IndexError: _LOGGING.error('Device name required.') self.do_help('set_workdir') if workdir: self.tools.workdir = workdir
python
def do_set_workdir(self, args): """Set the working directory. The working directory is used to load and save known devices to improve startup times. During startup the application loads and saves a file `insteon_plm_device_info.dat`. This file is saved in the working directory. The working directory has no default value. If the working directory is not set, the `insteon_plm_device_info.dat` file is not loaded or saved. Usage: set_workdir workdir Arguments: workdir: Required - Working directory to load and save devie list """ params = args.split() workdir = None try: workdir = params[0] except IndexError: _LOGGING.error('Device name required.') self.do_help('set_workdir') if workdir: self.tools.workdir = workdir
[ "def", "do_set_workdir", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "workdir", "=", "None", "try", ":", "workdir", "=", "params", "[", "0", "]", "except", "IndexError", ":", "_LOGGING", ".", "error", "(", "'Dev...
Set the working directory. The working directory is used to load and save known devices to improve startup times. During startup the application loads and saves a file `insteon_plm_device_info.dat`. This file is saved in the working directory. The working directory has no default value. If the working directory is not set, the `insteon_plm_device_info.dat` file is not loaded or saved. Usage: set_workdir workdir Arguments: workdir: Required - Working directory to load and save devie list
[ "Set", "the", "working", "directory", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L877-L903
train
39,384
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_help
def do_help(self, arg): """Help command. Usage: help [command] Parameters: command: Optional - command name to display detailed help """ cmds = arg.split() if cmds: func = getattr(self, 'do_{}'.format(cmds[0])) if func: _LOGGING.info(func.__doc__) else: _LOGGING.error('Command %s not found', cmds[0]) else: _LOGGING.info("Available command list: ") for curr_cmd in dir(self.__class__): if curr_cmd.startswith("do_") and not curr_cmd == 'do_test': print(" - ", curr_cmd[3:]) _LOGGING.info("For help with a command type `help command`")
python
def do_help(self, arg): """Help command. Usage: help [command] Parameters: command: Optional - command name to display detailed help """ cmds = arg.split() if cmds: func = getattr(self, 'do_{}'.format(cmds[0])) if func: _LOGGING.info(func.__doc__) else: _LOGGING.error('Command %s not found', cmds[0]) else: _LOGGING.info("Available command list: ") for curr_cmd in dir(self.__class__): if curr_cmd.startswith("do_") and not curr_cmd == 'do_test': print(" - ", curr_cmd[3:]) _LOGGING.info("For help with a command type `help command`")
[ "def", "do_help", "(", "self", ",", "arg", ")", ":", "cmds", "=", "arg", ".", "split", "(", ")", "if", "cmds", ":", "func", "=", "getattr", "(", "self", ",", "'do_{}'", ".", "format", "(", "cmds", "[", "0", "]", ")", ")", "if", "func", ":", "...
Help command. Usage: help [command] Parameters: command: Optional - command name to display detailed help
[ "Help", "command", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L905-L927
train
39,385
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_add_device_override
def do_add_device_override(self, args): """Add a device override to the IM. Usage: add_device_override address cat subcat [firmware] Arguments: address: Insteon address of the device to override cat: Device category subcat: Device subcategory firmware: Optional - Device firmware The device address can be written with our without the dots and in upper or lower case, for example: 1a2b3c or 1A.2B.3C. The category, subcategory and firmware numbers are written in hex format, for example: 0x01 0x1b Example: add_device_override 1a2b3c 0x02 0x1a """ params = args.split() addr = None cat = None subcat = None firmware = None error = None try: addr = Address(params[0]) cat = binascii.unhexlify(params[1][2:]) subcat = binascii.unhexlify(params[2][2:]) firmware = binascii.unhexlify(params[3][2:]) except IndexError: error = 'missing' except ValueError: error = 'value' if addr and cat and subcat: self.tools.add_device_override(addr, cat, subcat, firmware) else: if error == 'missing': _LOGGING.error('Device address, category and subcategory are ' 'required.') else: _LOGGING.error('Check the vales for address, category and ' 'subcategory.') self.do_help('add_device_override')
python
def do_add_device_override(self, args): """Add a device override to the IM. Usage: add_device_override address cat subcat [firmware] Arguments: address: Insteon address of the device to override cat: Device category subcat: Device subcategory firmware: Optional - Device firmware The device address can be written with our without the dots and in upper or lower case, for example: 1a2b3c or 1A.2B.3C. The category, subcategory and firmware numbers are written in hex format, for example: 0x01 0x1b Example: add_device_override 1a2b3c 0x02 0x1a """ params = args.split() addr = None cat = None subcat = None firmware = None error = None try: addr = Address(params[0]) cat = binascii.unhexlify(params[1][2:]) subcat = binascii.unhexlify(params[2][2:]) firmware = binascii.unhexlify(params[3][2:]) except IndexError: error = 'missing' except ValueError: error = 'value' if addr and cat and subcat: self.tools.add_device_override(addr, cat, subcat, firmware) else: if error == 'missing': _LOGGING.error('Device address, category and subcategory are ' 'required.') else: _LOGGING.error('Check the vales for address, category and ' 'subcategory.') self.do_help('add_device_override')
[ "def", "do_add_device_override", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "addr", "=", "None", "cat", "=", "None", "subcat", "=", "None", "firmware", "=", "None", "error", "=", "None", "try", ":", "addr", "="...
Add a device override to the IM. Usage: add_device_override address cat subcat [firmware] Arguments: address: Insteon address of the device to override cat: Device category subcat: Device subcategory firmware: Optional - Device firmware The device address can be written with our without the dots and in upper or lower case, for example: 1a2b3c or 1A.2B.3C. The category, subcategory and firmware numbers are written in hex format, for example: 0x01 0x1b Example: add_device_override 1a2b3c 0x02 0x1a
[ "Add", "a", "device", "override", "to", "the", "IM", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L945-L992
train
39,386
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_add_x10_device
def do_add_x10_device(self, args): """Add an X10 device to the IM. Usage: add_x10_device housecode unitcode type Arguments: housecode: Device housecode (A - P) unitcode: Device unitcode (1 - 16) type: Device type Current device types are: - OnOff - Dimmable - Sensor Example: add_x10_device M 12 OnOff """ params = args.split() housecode = None unitcode = None dev_type = None try: housecode = params[0] unitcode = int(params[1]) if unitcode not in range(1, 17): raise ValueError dev_type = params[2] except IndexError: pass except ValueError: _LOGGING.error('X10 unit code must be an integer 1 - 16') unitcode = None if housecode and unitcode and dev_type: device = self.tools.add_x10_device(housecode, unitcode, dev_type) if not device: _LOGGING.error('Device not added. Please check the ' 'information you provided.') self.do_help('add_x10_device') else: _LOGGING.error('Device housecode, unitcode and type are ' 'required.') self.do_help('add_x10_device')
python
def do_add_x10_device(self, args): """Add an X10 device to the IM. Usage: add_x10_device housecode unitcode type Arguments: housecode: Device housecode (A - P) unitcode: Device unitcode (1 - 16) type: Device type Current device types are: - OnOff - Dimmable - Sensor Example: add_x10_device M 12 OnOff """ params = args.split() housecode = None unitcode = None dev_type = None try: housecode = params[0] unitcode = int(params[1]) if unitcode not in range(1, 17): raise ValueError dev_type = params[2] except IndexError: pass except ValueError: _LOGGING.error('X10 unit code must be an integer 1 - 16') unitcode = None if housecode and unitcode and dev_type: device = self.tools.add_x10_device(housecode, unitcode, dev_type) if not device: _LOGGING.error('Device not added. Please check the ' 'information you provided.') self.do_help('add_x10_device') else: _LOGGING.error('Device housecode, unitcode and type are ' 'required.') self.do_help('add_x10_device')
[ "def", "do_add_x10_device", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "housecode", "=", "None", "unitcode", "=", "None", "dev_type", "=", "None", "try", ":", "housecode", "=", "params", "[", "0", "]", "unitcode"...
Add an X10 device to the IM. Usage: add_x10_device housecode unitcode type Arguments: housecode: Device housecode (A - P) unitcode: Device unitcode (1 - 16) type: Device type Current device types are: - OnOff - Dimmable - Sensor Example: add_x10_device M 12 OnOff
[ "Add", "an", "X10", "device", "to", "the", "IM", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L994-L1039
train
39,387
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_kpl_status
def do_kpl_status(self, args): """Get the status of a KeypadLinc button. Usage: kpl_status address group """ params = args.split() address = None group = None try: address = params[0] group = int(params[1]) except IndexError: _LOGGING.error("Address and group are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group: self.tools.kpl_status(address, group)
python
def do_kpl_status(self, args): """Get the status of a KeypadLinc button. Usage: kpl_status address group """ params = args.split() address = None group = None try: address = params[0] group = int(params[1]) except IndexError: _LOGGING.error("Address and group are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group: self.tools.kpl_status(address, group)
[ "def", "do_kpl_status", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "address", "=", "None", "group", "=", "None", "try", ":", "address", "=", "params", "[", "0", "]", "group", "=", "int", "(", "params", "[", ...
Get the status of a KeypadLinc button. Usage: kpl_status address group
[ "Get", "the", "status", "of", "a", "KeypadLinc", "button", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L1041-L1062
train
39,388
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_kpl_on
def do_kpl_on(self, args): """Turn on a KeypadLinc button. Usage: kpl_on address group """ params = args.split() address = None group = None try: address = params[0] group = int(params[1]) except IndexError: _LOGGING.error("Address and group are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group: self.tools.kpl_on(address, group)
python
def do_kpl_on(self, args): """Turn on a KeypadLinc button. Usage: kpl_on address group """ params = args.split() address = None group = None try: address = params[0] group = int(params[1]) except IndexError: _LOGGING.error("Address and group are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group: self.tools.kpl_on(address, group)
[ "def", "do_kpl_on", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "address", "=", "None", "group", "=", "None", "try", ":", "address", "=", "params", "[", "0", "]", "group", "=", "int", "(", "params", "[", "1"...
Turn on a KeypadLinc button. Usage: kpl_on address group
[ "Turn", "on", "a", "KeypadLinc", "button", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L1064-L1085
train
39,389
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_kpl_off
def do_kpl_off(self, args): """Turn off a KeypadLinc button. Usage: kpl_on address group """ params = args.split() address = None group = None try: address = params[0] group = int(params[1]) except IndexError: _LOGGING.error("Address and group are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group: self.tools.kpl_off(address, group)
python
def do_kpl_off(self, args): """Turn off a KeypadLinc button. Usage: kpl_on address group """ params = args.split() address = None group = None try: address = params[0] group = int(params[1]) except IndexError: _LOGGING.error("Address and group are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group: self.tools.kpl_off(address, group)
[ "def", "do_kpl_off", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "address", "=", "None", "group", "=", "None", "try", ":", "address", "=", "params", "[", "0", "]", "group", "=", "int", "(", "params", "[", "1...
Turn off a KeypadLinc button. Usage: kpl_on address group
[ "Turn", "off", "a", "KeypadLinc", "button", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L1087-L1108
train
39,390
nugget/python-insteonplm
insteonplm/tools.py
Commander.do_kpl_set_on_mask
def do_kpl_set_on_mask(self, args): """Set the on mask for a KeypadLinc button. Usage: kpl_set_on_mask address group mask """ params = args.split() address = None group = None mask_string = None mask = None try: address = params[0] group = int(params[1]) mask_string = params[2] if mask_string[0:2].lower() == '0x': mask = binascii.unhexlify(mask_string[2:]) else: mask = int(mask_string) except IndexError: _LOGGING.error("Address, group and mask are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group and mask: self.tools.kpl_set_on_mask(address, group, mask)
python
def do_kpl_set_on_mask(self, args): """Set the on mask for a KeypadLinc button. Usage: kpl_set_on_mask address group mask """ params = args.split() address = None group = None mask_string = None mask = None try: address = params[0] group = int(params[1]) mask_string = params[2] if mask_string[0:2].lower() == '0x': mask = binascii.unhexlify(mask_string[2:]) else: mask = int(mask_string) except IndexError: _LOGGING.error("Address, group and mask are regquired") self.do_help('kpl_status') except TypeError: _LOGGING.error("Group must be an integer") self.do_help('kpl_status') if address and group and mask: self.tools.kpl_set_on_mask(address, group, mask)
[ "def", "do_kpl_set_on_mask", "(", "self", ",", "args", ")", ":", "params", "=", "args", ".", "split", "(", ")", "address", "=", "None", "group", "=", "None", "mask_string", "=", "None", "mask", "=", "None", "try", ":", "address", "=", "params", "[", ...
Set the on mask for a KeypadLinc button. Usage: kpl_set_on_mask address group mask
[ "Set", "the", "on", "mask", "for", "a", "KeypadLinc", "button", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/tools.py#L1110-L1138
train
39,391
nugget/python-insteonplm
insteonplm/messages/userdata.py
Userdata.from_raw_message
def from_raw_message(cls, rawmessage): """Create a user data instance from a raw byte stream.""" empty = cls.create_empty(0x00) userdata_dict = cls.normalize(empty, rawmessage) return Userdata(userdata_dict)
python
def from_raw_message(cls, rawmessage): """Create a user data instance from a raw byte stream.""" empty = cls.create_empty(0x00) userdata_dict = cls.normalize(empty, rawmessage) return Userdata(userdata_dict)
[ "def", "from_raw_message", "(", "cls", ",", "rawmessage", ")", ":", "empty", "=", "cls", ".", "create_empty", "(", "0x00", ")", "userdata_dict", "=", "cls", ".", "normalize", "(", "empty", ",", "rawmessage", ")", "return", "Userdata", "(", "userdata_dict", ...
Create a user data instance from a raw byte stream.
[ "Create", "a", "user", "data", "instance", "from", "a", "raw", "byte", "stream", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/userdata.py#L83-L87
train
39,392
nugget/python-insteonplm
insteonplm/messages/userdata.py
Userdata.create_pattern
def create_pattern(cls, userdata): """Create a user data instance with all values the same.""" empty = cls.create_empty(None) userdata_dict = cls.normalize(empty, userdata) return Userdata(userdata_dict)
python
def create_pattern(cls, userdata): """Create a user data instance with all values the same.""" empty = cls.create_empty(None) userdata_dict = cls.normalize(empty, userdata) return Userdata(userdata_dict)
[ "def", "create_pattern", "(", "cls", ",", "userdata", ")", ":", "empty", "=", "cls", ".", "create_empty", "(", "None", ")", "userdata_dict", "=", "cls", ".", "normalize", "(", "empty", ",", "userdata", ")", "return", "Userdata", "(", "userdata_dict", ")" ]
Create a user data instance with all values the same.
[ "Create", "a", "user", "data", "instance", "with", "all", "values", "the", "same", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/userdata.py#L90-L94
train
39,393
nugget/python-insteonplm
insteonplm/messages/userdata.py
Userdata.template
def template(cls, userdata): """Create a template instance used for message callbacks.""" ud = Userdata(cls.normalize(cls.create_empty(None), userdata)) return ud
python
def template(cls, userdata): """Create a template instance used for message callbacks.""" ud = Userdata(cls.normalize(cls.create_empty(None), userdata)) return ud
[ "def", "template", "(", "cls", ",", "userdata", ")", ":", "ud", "=", "Userdata", "(", "cls", ".", "normalize", "(", "cls", ".", "create_empty", "(", "None", ")", ",", "userdata", ")", ")", "return", "ud" ]
Create a template instance used for message callbacks.
[ "Create", "a", "template", "instance", "used", "for", "message", "callbacks", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/userdata.py#L103-L106
train
39,394
nugget/python-insteonplm
insteonplm/messages/userdata.py
Userdata.matches_pattern
def matches_pattern(self, other): """Test if the current instance matches a template instance.""" ismatch = False if isinstance(other, Userdata): for key in self._userdata: if self._userdata[key] is None or other[key] is None: ismatch = True elif self._userdata[key] == other[key]: ismatch = True else: ismatch = False break return ismatch
python
def matches_pattern(self, other): """Test if the current instance matches a template instance.""" ismatch = False if isinstance(other, Userdata): for key in self._userdata: if self._userdata[key] is None or other[key] is None: ismatch = True elif self._userdata[key] == other[key]: ismatch = True else: ismatch = False break return ismatch
[ "def", "matches_pattern", "(", "self", ",", "other", ")", ":", "ismatch", "=", "False", "if", "isinstance", "(", "other", ",", "Userdata", ")", ":", "for", "key", "in", "self", ".", "_userdata", ":", "if", "self", ".", "_userdata", "[", "key", "]", "...
Test if the current instance matches a template instance.
[ "Test", "if", "the", "current", "instance", "matches", "a", "template", "instance", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/userdata.py#L108-L120
train
39,395
nugget/python-insteonplm
insteonplm/messages/userdata.py
Userdata.create_empty
def create_empty(cls, val=0x00): """Create an empty Userdata object. val: value to fill the empty user data fields with (default is 0x00) """ userdata_dict = {} for i in range(1, 15): key = 'd{}'.format(i) userdata_dict.update({key: val}) return userdata_dict
python
def create_empty(cls, val=0x00): """Create an empty Userdata object. val: value to fill the empty user data fields with (default is 0x00) """ userdata_dict = {} for i in range(1, 15): key = 'd{}'.format(i) userdata_dict.update({key: val}) return userdata_dict
[ "def", "create_empty", "(", "cls", ",", "val", "=", "0x00", ")", ":", "userdata_dict", "=", "{", "}", "for", "i", "in", "range", "(", "1", ",", "15", ")", ":", "key", "=", "'d{}'", ".", "format", "(", "i", ")", "userdata_dict", ".", "update", "("...
Create an empty Userdata object. val: value to fill the empty user data fields with (default is 0x00)
[ "Create", "an", "empty", "Userdata", "object", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/userdata.py#L150-L159
train
39,396
nugget/python-insteonplm
insteonplm/messages/userdata.py
Userdata.normalize
def normalize(cls, empty, userdata): """Return normalized user data as a dictionary. empty: an empty dictionary userdata: data in the form of Userdata, dict or None """ if isinstance(userdata, Userdata): return userdata.to_dict() if isinstance(userdata, dict): return cls._dict_to_dict(empty, userdata) if isinstance(userdata, (bytes, bytearray)): return cls._bytes_to_dict(empty, userdata) if userdata is None: return empty raise ValueError
python
def normalize(cls, empty, userdata): """Return normalized user data as a dictionary. empty: an empty dictionary userdata: data in the form of Userdata, dict or None """ if isinstance(userdata, Userdata): return userdata.to_dict() if isinstance(userdata, dict): return cls._dict_to_dict(empty, userdata) if isinstance(userdata, (bytes, bytearray)): return cls._bytes_to_dict(empty, userdata) if userdata is None: return empty raise ValueError
[ "def", "normalize", "(", "cls", ",", "empty", ",", "userdata", ")", ":", "if", "isinstance", "(", "userdata", ",", "Userdata", ")", ":", "return", "userdata", ".", "to_dict", "(", ")", "if", "isinstance", "(", "userdata", ",", "dict", ")", ":", "return...
Return normalized user data as a dictionary. empty: an empty dictionary userdata: data in the form of Userdata, dict or None
[ "Return", "normalized", "user", "data", "as", "a", "dictionary", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/userdata.py#L162-L176
train
39,397
nugget/python-insteonplm
insteonplm/messages/message.py
Message.hex
def hex(self): """Hexideciaml representation of the message in bytes.""" props = self._message_properties() msg = bytearray([MESSAGE_START_CODE_0X02, self._code]) for prop in props: # pylint: disable=unused-variable for key, val in prop.items(): if val is None: pass elif isinstance(val, int): msg.append(val) elif isinstance(val, Address): if val.addr is None: pass else: msg.extend(val.bytes) elif isinstance(val, MessageFlags): msg.extend(val.bytes) elif isinstance(val, bytearray): msg.extend(val) elif isinstance(val, bytes): msg.extend(val) elif isinstance(val, Userdata): msg.extend(val.bytes) return binascii.hexlify(msg).decode()
python
def hex(self): """Hexideciaml representation of the message in bytes.""" props = self._message_properties() msg = bytearray([MESSAGE_START_CODE_0X02, self._code]) for prop in props: # pylint: disable=unused-variable for key, val in prop.items(): if val is None: pass elif isinstance(val, int): msg.append(val) elif isinstance(val, Address): if val.addr is None: pass else: msg.extend(val.bytes) elif isinstance(val, MessageFlags): msg.extend(val.bytes) elif isinstance(val, bytearray): msg.extend(val) elif isinstance(val, bytes): msg.extend(val) elif isinstance(val, Userdata): msg.extend(val.bytes) return binascii.hexlify(msg).decode()
[ "def", "hex", "(", "self", ")", ":", "props", "=", "self", ".", "_message_properties", "(", ")", "msg", "=", "bytearray", "(", "[", "MESSAGE_START_CODE_0X02", ",", "self", ".", "_code", "]", ")", "for", "prop", "in", "props", ":", "# pylint: disable=unused...
Hexideciaml representation of the message in bytes.
[ "Hexideciaml", "representation", "of", "the", "message", "in", "bytes", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/message.py#L131-L157
train
39,398
nugget/python-insteonplm
insteonplm/messages/message.py
Message.matches_pattern
def matches_pattern(self, other): """Return if the current message matches a message template. Compare the current message to a template message to test matches to a pattern. """ properties = self._message_properties() ismatch = False if isinstance(other, Message) and self.code == other.code: for prop in properties: for key, prop_val in prop.items(): if hasattr(other, key): key_val = getattr(other, key) ismatch = self._test_match(prop_val, key_val) else: ismatch = False if not ismatch: break if not ismatch: break return ismatch
python
def matches_pattern(self, other): """Return if the current message matches a message template. Compare the current message to a template message to test matches to a pattern. """ properties = self._message_properties() ismatch = False if isinstance(other, Message) and self.code == other.code: for prop in properties: for key, prop_val in prop.items(): if hasattr(other, key): key_val = getattr(other, key) ismatch = self._test_match(prop_val, key_val) else: ismatch = False if not ismatch: break if not ismatch: break return ismatch
[ "def", "matches_pattern", "(", "self", ",", "other", ")", ":", "properties", "=", "self", ".", "_message_properties", "(", ")", "ismatch", "=", "False", "if", "isinstance", "(", "other", ",", "Message", ")", "and", "self", ".", "code", "==", "other", "."...
Return if the current message matches a message template. Compare the current message to a template message to test matches to a pattern.
[ "Return", "if", "the", "current", "message", "matches", "a", "message", "template", "." ]
65548041f1b0729ae1ae904443dd81b0c6cbf1bf
https://github.com/nugget/python-insteonplm/blob/65548041f1b0729ae1ae904443dd81b0c6cbf1bf/insteonplm/messages/message.py#L164-L184
train
39,399