text
stringlengths
0
828
if len(ret) == 0:
raise RuntimeError(""key '{0!s}' has no valid characters to be a key in a FITS header"".format(key))
return ret"
3863,"def eval_fieldnames(string_, varname=""fieldnames""):
""""""Evaluates string_, must evaluate to list of strings. Also converts field names to uppercase""""""
ff = eval(string_)
if not isinstance(ff, list):
raise RuntimeError(""{0!s} must be a list"".format(varname))
if not all([isinstance(x, str) for x in ff]):
raise RuntimeError(""{0!s} must be a list of strings"".format(varname))
ff = [x.upper() for x in ff]
return ff"
3864,"def module_to_dict(module):
""""""Creates a dictionary whose keys are module.__all__
Returns: {""(attribute name)"": attribute, ...}
""""""
lot = [(key, module.__getattribute__(key)) for key in module.__all__]
ret = dict(lot)
return ret"
3865,"def strip_accents(s):
""""""
Strip accents to prepare for slugification.
""""""
nfkd = unicodedata.normalize('NFKD', unicode(s))
return u''.join(ch for ch in nfkd if not unicodedata.combining(ch))"
3866,"def slugify(s):
""""""
Converts the given string to a URL slug.
""""""
s = strip_accents(s.replace(""'"", '').lower())
return re.sub('[^a-z0-9]+', ' ', s).strip().replace(' ', '-')"
3867,"def _legacy_status(stat):
""""""Legacy status method from the 'qsmobile.js' library.
Pass in the 'val' from &devices or the
'data' received after calling a specific ID.
""""""
# 2d0c00002a0000
if stat[:2] == '30' or stat[:2] == '47': # RX1 CT
ooo = stat[4:5]
# console.log(""legstat. "" + o);
if ooo == '0':
return 0
if ooo == '8':
return 100
if stat == '7e':
return 0
if stat == '7f':
return 100
if len(stat) == 6: # old
try:
val = int(stat[4:], 16)
except ValueError:
val = 0
hwt = stat[:2]
if hwt == '01': # old dim
return round(((125 - val) / 125) * 100)
if hwt == '02': # old rel
return 100 if val == 127 else 0
if hwt == '28': # LED DIM
if stat[2:4] == '01':
if stat[4:] == '78':
return 0
return round(((120 - val) / 120) * 100)
# Additional decodes not part of qsmobile.js
if stat.upper().find('ON') >= 0: # Relay
return 100
if (not stat) or stat.upper().find('OFF') >= 0:
return 0
if stat.endswith('%'): # New style dimmers
if stat[:-1].isdigit:
return int(stat[:-1])
_LOGGER.debug(""val='%s' used a -1 fallback in legacy_status"", stat)
return -1"
3868,"def decode_qwikcord(packet, channel=1):
""""""Extract the qwikcord current measurements from val (CTavg, CTsum).""""""
val = str(packet.get('val', ''))
if len(val) != 16:
return None
if channel == 1:
return int(val[6:12], 16) # CTavg
return int(val[12:], 16)"
3869,"def decode_door(packet, channel=1):
""""""Decode a door sensor.""""""
val = str(packet.get(QSDATA, ''))
if len(val) == 6 and val.startswith('46') and channel == 1:
return val[-1] == '0'
return None"
3870,"def decode_imod(packet, channel=1):
""""""Decode an 4 channel imod. May support 6 channels.""""""
val = str(packet.get(QSDATA, ''))
if len(val) == 8 and val.startswith('4e'):
try:
_map = ((5, 1), (5, 2), (5, 4), (4, 1), (5, 1), (5, 2))[
channel - 1]
return (int(val[_map[0]], 16) & _map[1]) == 0
except IndexError: