sentence1 stringlengths 52 3.87M | sentence2 stringlengths 1 47.2k | label stringclasses 1
value |
|---|---|---|
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':
_... | Set the log level.
Usage:
set_log_level i|v
Parameters:
log_level: i - info | v - verbose | entailment |
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 = ... | Set the PLM OS device.
Device defaults to /dev/ttyUSB0
Usage:
set_device device
Arguments:
device: Required - INSTEON PLM device | entailment |
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.
... | 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 defau... | entailment |
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:
... | Help command.
Usage:
help [command]
Parameters:
command: Optional - command name to display detailed help | entailment |
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
... | 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
... | entailment |
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 ar... | 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
... | entailment |
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 Inde... | Get the status of a KeypadLinc button.
Usage:
kpl_status address group | entailment |
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:
... | Turn on a KeypadLinc button.
Usage:
kpl_on address group | entailment |
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:
... | Turn off a KeypadLinc button.
Usage:
kpl_on address group | entailment |
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 = ... | Set the on mask for a KeypadLinc button.
Usage:
kpl_set_on_mask address group mask | entailment |
def human(self):
"""Emit the address in human-readible format (AA.BB.CC)."""
strout = ''
first = True
for i in range(0, 28, 2):
if first:
first = False
else:
strout = strout + '.'
strout = strout + self.hex[i:i + 2]
... | Emit the address in human-readible format (AA.BB.CC). | entailment |
def bytes(self):
"""Emit the address in bytes format."""
byteout = bytearray()
for i in range(1, 15):
key = 'd' + str(i)
if self._userdata[key] is not None:
byteout.append(self._userdata[key])
else:
byteout.append(0x00)
... | Emit the address in bytes format. | entailment |
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) | Create a user data instance from a raw byte stream. | entailment |
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) | Create a user data instance with all values the same. | entailment |
def template(cls, userdata):
"""Create a template instance used for message callbacks."""
ud = Userdata(cls.normalize(cls.create_empty(None), userdata))
return ud | Create a template instance used for message callbacks. | entailment |
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
... | Test if the current instance matches a template instance. | entailment |
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 u... | Create an empty Userdata object.
val: value to fill the empty user data fields with (default is 0x00) | entailment |
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 normalized user data as a dictionary.
empty: an empty dictionary
userdata: data in the form of Userdata, dict or None | entailment |
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():
i... | Hexideciaml representation of the message in bytes. | entailment |
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... | Return if the current message matches a message template.
Compare the current message to a template message to test matches
to a pattern. | entailment |
def _register_messages(self):
"""Register messages to listen for."""
template_on_group = StandardReceive.template(
commandtuple=COMMAND_LIGHT_ON_0X11_NONE,
address=self._address,
target=bytearray([0x00, 0x00, self._group]),
flags=MessageFlags.template(MESS... | Register messages to listen for. | entailment |
def on(self):
"""Send ON command to device."""
on_command = StandardSend(self._address,
COMMAND_LIGHT_ON_0X11_NONE, 0xff)
self._send_method(on_command,
self._on_message_received) | Send ON command to device. | entailment |
def off(self):
"""Send OFF command to device."""
self._send_method(StandardSend(self._address,
COMMAND_LIGHT_OFF_0X13_0X00),
self._off_message_received) | Send OFF command to device. | entailment |
def _send_status_0x01_request(self):
"""Sent status request to device."""
status_command = StandardSend(self._address,
COMMAND_LIGHT_STATUS_REQUEST_0X19_0X01)
self._send_method(status_command, self._status_message_0x01_received) | Sent status request to device. | entailment |
def _status_message_0x01_received(self, msg):
"""Handle status received messages.
The following status values can be received:
0x00 = Both Outlets Off
0x01 = Only Top Outlet On
0x02 = Only Bottom Outlet On
0x03 = Both Outlets On
"""
if msg... | Handle status received messages.
The following status values can be received:
0x00 = Both Outlets Off
0x01 = Only Top Outlet On
0x02 = Only Bottom Outlet On
0x03 = Both Outlets On | entailment |
def on(self):
"""Send an ON message to device group."""
on_command = ExtendedSend(self._address,
COMMAND_LIGHT_ON_0X11_NONE,
self._udata,
cmd2=0xff)
on_command.set_checksum()
self._send_... | Send an ON message to device group. | entailment |
def off(self):
"""Send an OFF message to device group."""
off_command = ExtendedSend(self._address,
COMMAND_LIGHT_OFF_0X13_0X00,
self._udata)
off_command.set_checksum()
self._send_method(off_command, self._off_message_... | Send an OFF message to device group. | entailment |
def _send_status_0x01_request(self):
"""Send a status request."""
status_command = StandardSend(self._address,
COMMAND_LIGHT_STATUS_REQUEST_0X19_0X01)
self._send_method(status_command, self._status_message_received) | Send a status request. | entailment |
def _status_message_received(self, msg):
"""Receive a status message.
The following status values can be received:
0x00 = Both Outlets Off
0x01 = Only Top Outlet On
0x02 = Only Bottom Outlet On
0x03 = Both Outlets On
"""
if msg.cmd2 == 0x0... | Receive a status message.
The following status values can be received:
0x00 = Both Outlets Off
0x01 = Only Top Outlet On
0x02 = Only Bottom Outlet On
0x03 = Both Outlets On | entailment |
def close(self):
"""Send CLOSE command to device."""
close_command = StandardSend(self._address,
COMMAND_LIGHT_OFF_0X13_0X00)
self._send_method(close_command, self._close_message_received) | Send CLOSE command to device. | entailment |
def led_changed(self, addr, group, val):
"""Capture a change to the LED for this button."""
_LOGGER.debug("Button %d LED changed from %d to %d",
self._group, self._value, val)
led_on = bool(val)
if led_on != bool(self._value):
self._update_subscribers(in... | Capture a change to the LED for this button. | entailment |
def set_on_mask(self, mask):
"""Set the on mask for the current group/button."""
set_cmd = self._create_set_property_msg('_on_mask', 0x02, mask)
self._send_method(set_cmd, self._property_set) | Set the on mask for the current group/button. | entailment |
def set_off_mask(self, mask):
"""Set the off mask for the current group/button."""
set_cmd = self._create_set_property_msg('_off_mask', 0x03, mask)
self._send_method(set_cmd, self._property_set) | Set the off mask for the current group/button. | entailment |
def set_x10_address(self, x10address):
"""Set the X10 address for the current group/button."""
set_cmd = self._create_set_property_msg('_x10_house_code', 0x04,
x10address)
self._send_method(set_cmd, self._property_set) | Set the X10 address for the current group/button. | entailment |
def set_ramp_rate(self, ramp_rate):
"""Set the X10 address for the current group/button."""
set_cmd = self._create_set_property_msg('_ramp_rate', 0x05,
ramp_rate)
self._send_method(set_cmd, self._property_set) | Set the X10 address for the current group/button. | entailment |
def set_on_level(self, val):
"""Set on level for the button/group."""
on_cmd = self._create_set_property_msg("_on_level", 0x06,
val)
self._send_method(on_cmd, self._property_set)
self._send_method(on_cmd, self._on_message_received) | Set on level for the button/group. | entailment |
def set_led_brightness(self, brightness):
"""Set the LED brightness for the current group/button."""
set_cmd = self._create_set_property_msg("_led_brightness", 0x07,
brightness)
self._send_method(set_cmd, self._property_set) | Set the LED brightness for the current group/button. | entailment |
def set_non_toggle_mask(self, non_toggle_mask):
"""Set the non_toggle_mask for the current group/button."""
set_cmd = self._create_set_property_msg("_non_toggle_mask", 0x08,
non_toggle_mask)
self._send_method(set_cmd, self._property_set) | Set the non_toggle_mask for the current group/button. | entailment |
def set_x10_all_bit_mask(self, x10_all_bit_mask):
"""Set the x10_all_bit_mask for the current group/button."""
set_cmd = self._create_set_property_msg("_x10_all_bit_mask", 0x0a,
x10_all_bit_mask)
self._send_method(set_cmd, self._property_set) | Set the x10_all_bit_mask for the current group/button. | entailment |
def set_trigger_group_bit_mask(self, trigger_group_bit_mask):
"""Set the trigger_group_bit_mask for the current group/button."""
set_cmd = self._create_set_property_msg("_trigger_group_bit_mask",
0x0c, trigger_group_bit_mask)
self._send_method(set_... | Set the trigger_group_bit_mask for the current group/button. | entailment |
def scene_on(self):
"""Trigger group/scene to ON level."""
user_data = Userdata({'d1': self._group,
'd2': 0x00,
'd3': 0x00,
'd4': 0x11,
'd5': 0xff,
'd6': ... | Trigger group/scene to ON level. | entailment |
def scene_off(self):
"""Trigger group/scene to OFF level."""
user_data = Userdata({'d1': self._group,
'd2': 0x00,
'd3': 0x00,
'd4': 0x13,
'd5': 0x00,
'd6'... | Trigger group/scene to OFF level. | entailment |
def extended_status_request(self):
"""Send status request for group/button."""
self._status_received = False
user_data = Userdata({'d1': self.group,
'd2': 0x00})
cmd = ExtendedSend(self._address,
COMMAND_EXTENDED_GET_SET_0X2E_0X00,... | Send status request for group/button. | entailment |
def _status_message_received(self, msg):
"""Receive confirmation that the status message is coming.
The real status message is the extended direct message.
"""
if not self._status_received:
asyncio.ensure_future(self._confirm_status_received(),
... | Receive confirmation that the status message is coming.
The real status message is the extended direct message. | entailment |
def _status_extended_message_received(self, msg):
"""Receeive an extended status message.
Status message received:
cmd1: 0x2e
cmd2: 0x00
flags: Direct Extended
d1: group
d2: 0x01
d3: On Mask
d4: Off Mask
... | Receeive an extended status message.
Status message received:
cmd1: 0x2e
cmd2: 0x00
flags: Direct Extended
d1: group
d2: 0x01
d3: On Mask
d4: Off Mask
d5: X10 House Code
d6: X10 Unit
... | entailment |
def _property_set(self, msg):
"""Set command received and acknowledged."""
prop = self._sent_property.get('prop')
if prop and hasattr(self, prop):
setattr(self, prop, self._sent_property.get('val'))
self._sent_property = {} | Set command received and acknowledged. | entailment |
def _set_status_data(self, userdata):
"""Set status properties from userdata response.
Response values:
d3: On Mask
d4: Off Mask
d5: X10 House Code
d6: X10 Unit
d7: Ramp Rate
d8: On-Level
d9: LED Brightness
... | Set status properties from userdata response.
Response values:
d3: On Mask
d4: Off Mask
d5: X10 House Code
d6: X10 Unit
d7: Ramp Rate
d8: On-Level
d9: LED Brightness
d10: Non-Toggle Mask
d11: LED ... | entailment |
def _create_set_property_msg(self, prop, cmd, val):
"""Create an extended message to set a property.
Create an extended message with:
cmd1: 0x2e
cmd2: 0x00
flags: Direct Extended
d1: group
d2: cmd
d3: val
d4 - d14: 0x00... | Create an extended message to set a property.
Create an extended message with:
cmd1: 0x2e
cmd2: 0x00
flags: Direct Extended
d1: group
d2: cmd
d3: val
d4 - d14: 0x00
Parameters:
prop: Property name to update... | entailment |
def on(self, group):
"""Turn the LED on for a group."""
asyncio.ensure_future(self._send_led_on_off_request(group, 1),
loop=self._loop) | Turn the LED on for a group. | entailment |
def off(self, group):
"""Turn the LED off for a group."""
asyncio.ensure_future(self._send_led_on_off_request(group, 0),
loop=self._loop) | Turn the LED off for a group. | entailment |
def register_led_updates(self, callback, button):
"""Register a callback when a specific button LED changes."""
button_callbacks = self._button_observer_callbacks.get(button)
if not button_callbacks:
self._button_observer_callbacks[button] = []
_LOGGER.debug('New callback for... | Register a callback when a specific button LED changes. | entailment |
def _set_led_value(self, group, val):
"""Set the LED value and confirm with a status check."""
new_bitmask = set_bit(self._value, group, bool(val))
self._set_led_bitmask(new_bitmask) | Set the LED value and confirm with a status check. | entailment |
def _bit_value(self, group, val):
"""Set the LED on/off value from the LED bitmap."""
bitshift = group - 1
if val:
new_value = self._value | (1 << bitshift)
else:
new_value = self._value & (0xff & ~(1 << bitshift))
return new_value | Set the LED on/off value from the LED bitmap. | entailment |
def set(self, mode):
"""Set the thermostat mode.
Mode optons:
OFF = 0x00,
HEAT = 0x01,
COOL = 0x02,
AUTO = 0x03,
FAN_AUTO = 0x04,
FAN_ALWAYS_ON = 0x8
"""
new_mode = None
if mode == ThermostatMode.OFF:
... | Set the thermostat mode.
Mode optons:
OFF = 0x00,
HEAT = 0x01,
COOL = 0x02,
AUTO = 0x03,
FAN_AUTO = 0x04,
FAN_ALWAYS_ON = 0x8 | entailment |
def set(self, mode):
"""Set the thermostat mode.
Mode optons:
OFF = 0x00,
HEAT = 0x01,
COOL = 0x02,
AUTO = 0x03,
FAN_AUTO = 0x04,
FAN_ALWAYS_ON = 0x8
"""
if mode == ThermostatMode.FAN_AUTO:
new_mode = CO... | Set the thermostat mode.
Mode optons:
OFF = 0x00,
HEAT = 0x01,
COOL = 0x02,
AUTO = 0x03,
FAN_AUTO = 0x04,
FAN_ALWAYS_ON = 0x8 | entailment |
def set(self, val):
"""Set the cool set point."""
msg = ExtendedSend(
address=self._address,
commandtuple=COMMAND_THERMOSTAT_SET_COOL_SETPOINT_0X6C_NONE,
cmd2=int(val * 2),
userdata=Userdata())
msg.set_checksum()
self._send_method(msg, self... | Set the cool set point. | entailment |
def set(self, val):
"""Set the heat set point."""
msg = ExtendedSend(
address=self._address,
commandtuple=COMMAND_THERMOSTAT_SET_HEAT_SETPOINT_0X6D_NONE,
cmd2=int(val * 2),
userdata=Userdata())
msg.set_checksum()
self._send_method(msg, self... | Set the heat set point. | entailment |
def add_device_callback(self, callback):
"""Register a callback to be invoked when a new device appears."""
_LOGGER.debug('Added new callback %s ', callback)
self._cb_new_device.append(callback) | Register a callback to be invoked when a new device appears. | entailment |
def add_override(self, addr, key, value):
"""Register an attribute override for a device."""
address = Address(str(addr)).id
_LOGGER.debug('New override for %s %s is %s', address, key, value)
device_override = self._overrides.get(address, {})
device_override[key] = value
... | Register an attribute override for a device. | entailment |
def create_device_from_category(self, plm, addr, cat, subcat,
product_key=0x00):
"""Create a new device from the cat, subcat and product_key data."""
saved_device = self._saved_devices.get(Address(addr).id, {})
cat = saved_device.get('cat', cat)
subcat... | Create a new device from the cat, subcat and product_key data. | entailment |
def has_saved(self, addr):
"""Test if device has data from the saved data file."""
saved = False
if self._saved_devices.get(addr, None) is not None:
saved = True
return saved | Test if device has data from the saved data file. | entailment |
def has_override(self, addr):
"""Test if device has data from a device override setting."""
override = False
if self._overrides.get(addr, None) is not None:
override = True
return override | Test if device has data from a device override setting. | entailment |
def add_known_devices(self, plm):
"""Add devices from the saved devices or from the device overrides."""
from insteonplm.devices import ALDBStatus
for addr in self._saved_devices:
if not self._devices.get(addr):
saved_device = self._saved_devices.get(Address(addr).id,... | Add devices from the saved devices or from the device overrides. | entailment |
def save_device_info(self):
"""Save all device information to the device info file."""
if self._workdir is not None:
devices = []
for addr in self._devices:
device = self._devices.get(addr)
if not device.address.is_x10:
aldb = {... | Save all device information to the device info file. | entailment |
def _add_saved_device_info(self, **kwarg):
"""Register device info from the saved data file."""
addr = kwarg.get('address')
_LOGGER.debug('Found saved device with address %s', addr)
self._saved_devices[addr] = kwarg | Register device info from the saved data file. | entailment |
async def load_saved_device_info(self):
"""Load device information from the device info file."""
_LOGGER.debug("Loading saved device info.")
deviceinfo = []
if self._workdir:
_LOGGER.debug("Really Loading saved device info.")
try:
device_file = '{}... | Load device information from the device info file. | entailment |
def unit_code_msg(housecode, unitcode):
"""Create an X10 message to send the house code and unit code."""
house_byte = 0
unit_byte = 0
if isinstance(housecode, str):
house_byte = insteonplm.utils.housecode_to_byte(housecode) << 4
unit_byte = insteonplm.utils.unitc... | Create an X10 message to send the house code and unit code. | entailment |
def command_msg(housecode, command):
"""Create an X10 message to send the house code and a command code."""
house_byte = 0
if isinstance(housecode, str):
house_byte = insteonplm.utils.housecode_to_byte(housecode) << 4
elif isinstance(housecode, int) and housecode < 16:
... | Create an X10 message to send the house code and a command code. | entailment |
async def create_http_connection(loop, protocol_factory, host, port=25105,
auth=None):
"""Create an HTTP session used to connect to the Insteon Hub."""
protocol = protocol_factory()
transport = HttpTransport(loop, protocol, host, port, auth)
_LOGGER.debug("create_http_co... | Create an HTTP session used to connect to the Insteon Hub. | entailment |
async def create(cls, device='/dev/ttyUSB0', host=None,
username=None, password=None, port=25010, hub_version=2,
auto_reconnect=True, loop=None, workdir=None,
poll_devices=True, load_aldb=True):
"""Create a connection to a specific device.
... | Create a connection to a specific device.
Here is where we supply the device and callback callables we
expect for this PLM class object.
:param device:
Unix device where the PLM is attached
:param address:
IP Address of the Hub
:param username:
... | entailment |
async def reconnect(self):
"""Reconnect to the modem."""
_LOGGER.debug('starting Connection.reconnect')
await self._connect()
while self._closed:
await self._retry_connection()
_LOGGER.debug('ending Connection.reconnect') | Reconnect to the modem. | entailment |
async def close(self, event):
"""Close the PLM device connection and don't try to reconnect."""
_LOGGER.info('Closing connection to Insteon Modem')
self._closing = True
self._auto_reconnect = False
await self.protocol.close()
if self.protocol.transport:
self.p... | Close the PLM device connection and don't try to reconnect. | entailment |
def dump_conndata(self):
"""Developer tool for debugging forensics."""
attrs = vars(self)
return ', '.join("%s: %s" % item for item in attrs.items()) | Developer tool for debugging forensics. | entailment |
def on(self):
"""Send the On command to an X10 device."""
msg = X10Send.unit_code_msg(self.address.x10_housecode,
self.address.x10_unitcode)
self._send_method(msg)
msg = X10Send.command_msg(self.address.x10_housecode,
... | Send the On command to an X10 device. | entailment |
def off(self):
"""Send the Off command to an X10 device."""
msg = X10Send.unit_code_msg(self.address.x10_housecode,
self.address.x10_unitcode)
self._send_method(msg)
msg = X10Send.command_msg(self.address.x10_housecode,
... | Send the Off command to an X10 device. | entailment |
def set_level(self, val):
"""Set the device ON LEVEL."""
if val == 0:
self.off()
elif val == 255:
self.on()
else:
setlevel = 255
if val < 1:
setlevel = val * 255
elif val <= 0xff:
setlevel = val
... | Set the device ON LEVEL. | entailment |
def brighten(self, defer_update=False):
"""Brighten the device one step."""
msg = X10Send.unit_code_msg(self.address.x10_housecode,
self.address.x10_unitcode)
self._send_method(msg)
msg = X10Send.command_msg(self.address.x10_housecode,
... | Brighten the device one step. | entailment |
def dim(self, defer_update=False):
"""Dim the device one step."""
msg = X10Send.unit_code_msg(self.address.x10_housecode,
self.address.x10_unitcode)
self._send_method(msg)
msg = X10Send.command_msg(self.address.x10_housecode,
... | Dim the device one step. | entailment |
def matches_pattern(self, other):
"""Test Address object matches the pattern of another object."""
matches = False
if hasattr(other, 'addr'):
if self.addr is None or other.addr is None:
matches = True
else:
matches = self.addr == other.add... | Test Address object matches the pattern of another object. | entailment |
def _normalize(self, addr):
"""Take any format of address and turn it into a hex string."""
normalize = None
if isinstance(addr, Address):
normalize = addr.addr
self._is_x10 = addr.is_x10
elif isinstance(addr, bytearray):
normalize = binascii.unhexlif... | Take any format of address and turn it into a hex string. | entailment |
def human(self):
"""Emit the address in human-readible format (AA.BB.CC)."""
addrstr = '00.00.00'
if self.addr:
if self._is_x10:
housecode_byte = self.addr[1]
housecode = insteonplm.utils.byte_to_housecode(housecode_byte)
unitcode_byte ... | Emit the address in human-readible format (AA.BB.CC). | entailment |
def hex(self):
"""Emit the address in bare hex format (aabbcc)."""
addrstr = '000000'
if self.addr is not None:
addrstr = binascii.hexlify(self.addr).decode()
return addrstr | Emit the address in bare hex format (aabbcc). | entailment |
def bytes(self):
"""Emit the address in bytes format."""
addrbyte = b'\x00\x00\x00'
if self.addr is not None:
addrbyte = self.addr
return addrbyte | Emit the address in bytes format. | entailment |
def id(self):
"""Return the ID of the device address."""
dev_id = ''
if self._is_x10:
dev_id = 'x10{}{:02d}'.format(self.x10_housecode,
self.x10_unitcode)
else:
dev_id = self.hex
return dev_id | Return the ID of the device address. | entailment |
def x10_housecode(self):
"""Emit the X10 house code."""
housecode = None
if self.is_x10:
housecode = insteonplm.utils.byte_to_housecode(self.addr[1])
return housecode | Emit the X10 house code. | entailment |
def x10_unitcode(self):
"""Emit the X10 unit code."""
unitcode = None
if self.is_x10:
unitcode = insteonplm.utils.byte_to_unitcode(self.addr[2])
return unitcode | Emit the X10 unit code. | entailment |
def x10(cls, housecode, unitcode):
"""Create an X10 device address."""
if housecode.lower() in ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p']:
byte_housecode = insteonplm.utils.housecode_to_byte(housecode)
else:
... | Create an X10 device address. | entailment |
def from_raw_message(cls, rawmessage):
"""Create message from raw byte stream."""
return ManageAllLinkRecord(rawmessage[2:3],
rawmessage[3:4],
rawmessage[4:7],
rawmessage[7:8],
... | Create message from raw byte stream. | entailment |
def _term_to_xapian_value(term, field_type):
"""
Converts a term to a serialized
Xapian value based on the field_type.
"""
assert field_type in FIELD_TYPES
def strf(dt):
"""
Equivalent to datetime.datetime.strptime(dt, DATETIME_FORMAT)
but accepts years below 1900 (see h... | Converts a term to a serialized
Xapian value based on the field_type. | entailment |
def _from_xapian_value(value, field_type):
"""
Converts a serialized Xapian value
to Python equivalent based on the field_type.
Doesn't accept multivalued fields.
"""
assert field_type in FIELD_TYPES
if field_type == 'boolean':
if value == 't':
return True
elif v... | Converts a serialized Xapian value
to Python equivalent based on the field_type.
Doesn't accept multivalued fields. | entailment |
def _update_cache(self):
"""
To avoid build_schema every time, we cache
some values: they only change when a SearchIndex
changes, which typically restarts the Python.
"""
fields = connections[self.connection_alias].get_unified_index().all_searchfields()
if self._f... | To avoid build_schema every time, we cache
some values: they only change when a SearchIndex
changes, which typically restarts the Python. | entailment |
def update(self, index, iterable, commit=True):
"""
Updates the `index` with any objects in `iterable` by adding/updating
the database as needed.
Required arguments:
`index` -- The `SearchIndex` to process
`iterable` -- An iterable of model instances to index
... | Updates the `index` with any objects in `iterable` by adding/updating
the database as needed.
Required arguments:
`index` -- The `SearchIndex` to process
`iterable` -- An iterable of model instances to index
Optional arguments:
`commit` -- ignored
Fo... | entailment |
def remove(self, obj, commit=True):
"""
Remove indexes for `obj` from the database.
We delete all instances of `Q<app_name>.<model_name>.<pk>` which
should be unique to this object.
Optional arguments:
`commit` -- ignored
"""
database = self._database... | Remove indexes for `obj` from the database.
We delete all instances of `Q<app_name>.<model_name>.<pk>` which
should be unique to this object.
Optional arguments:
`commit` -- ignored | entailment |
def clear(self, models=(), commit=True):
"""
Clear all instances of `models` from the database or all models, if
not specified.
Optional Arguments:
`models` -- Models to clear from the database (default = [])
If `models` is empty, an empty query is executed which ma... | Clear all instances of `models` from the database or all models, if
not specified.
Optional Arguments:
`models` -- Models to clear from the database (default = [])
If `models` is empty, an empty query is executed which matches all
documents in the database. Afterwards, eac... | entailment |
def _build_models_query(self, query):
"""
Builds a query from `query` that filters to documents only from registered models.
"""
registered_models_ct = self.build_models_list()
if registered_models_ct:
restrictions = [xapian.Query('%s%s' % (TERM_PREFIXES[DJANGO_CT], m... | Builds a query from `query` that filters to documents only from registered models. | entailment |
def _check_field_names(self, field_names):
"""
Raises InvalidIndexError if any of a field_name in field_names is
not indexed.
"""
if field_names:
for field_name in field_names:
try:
self.column[field_name]
except Key... | Raises InvalidIndexError if any of a field_name in field_names is
not indexed. | entailment |
def search(self, query, sort_by=None, start_offset=0, end_offset=None,
fields='', highlight=False, facets=None, date_facets=None,
query_facets=None, narrow_queries=None, spelling_query=None,
limit_to_registered_models=None, result_class=None, **kwargs):
"""
E... | Executes the Xapian::query as defined in `query`.
Required arguments:
`query` -- Search query to execute
Optional arguments:
`sort_by` -- Sort results by specified field (default = None)
`start_offset` -- Slice results from `start_offset` (default = 0)
`... | entailment |
def more_like_this(self, model_instance, additional_query=None,
start_offset=0, end_offset=None,
limit_to_registered_models=True, result_class=None, **kwargs):
"""
Given a model instance, returns a result set of similar documents.
Required arguments... | Given a model instance, returns a result set of similar documents.
Required arguments:
`model_instance` -- The model instance to use as a basis for
retrieving similar documents.
Optional arguments:
`additional_query` -- An additional query to nar... | entailment |
def parse_query(self, query_string):
"""
Given a `query_string`, will attempt to return a xapian.Query
Required arguments:
``query_string`` -- A query string to parse
Returns a xapian.Query
"""
if query_string == '*':
return xapian.Query('') # M... | Given a `query_string`, will attempt to return a xapian.Query
Required arguments:
``query_string`` -- A query string to parse
Returns a xapian.Query | entailment |
def build_schema(self, fields):
"""
Build the schema from fields.
:param fields: A list of fields in the index
:returns: list of dictionaries
Each dictionary has the keys
field_name: The name of the field index
type: what type of value it is
'multi_va... | Build the schema from fields.
:param fields: A list of fields in the index
:returns: list of dictionaries
Each dictionary has the keys
field_name: The name of the field index
type: what type of value it is
'multi_valued': if it allows more than one value
'co... | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.