text stringlengths 0 828 |
|---|
return None |
return None" |
3871,"def decode_pir(packet, channel=1): |
""""""Decode a PIR."""""" |
val = str(packet.get(QSDATA, '')) |
if len(val) == 8 and val.startswith('0f') and channel == 1: |
return int(val[-4:], 16) > 0 |
return None" |
3872,"def decode_temperature(packet, channel=1): |
""""""Decode the temperature."""""" |
val = str(packet.get(QSDATA, '')) |
if len(val) == 12 and val.startswith('34') and channel == 1: |
temperature = int(val[-4:], 16) |
return round(float((-46.85 + (175.72 * (temperature / pow(2, 16)))))) |
return None" |
3873,"def decode_humidity(packet, channel=1): |
""""""Decode the humidity."""""" |
val = str(packet.get(QSDATA, '')) |
if len(val) == 12 and val.startswith('34') and channel == 1: |
humidity = int(val[4:-4], 16) |
return round(float(-6 + (125 * (humidity / pow(2, 16))))) |
return None" |
3874,"def set_value(self, qsid, new): |
# Set value & encode new to be passed to QSUSB |
""""""Set a value."""""" |
try: |
dev = self[qsid] |
except KeyError: |
raise KeyError(""Device {} not found"".format(qsid)) |
if new < 0: |
new = 0 |
if new == dev.value: |
return |
if dev.is_dimmer: |
new = _MAX if new > (_MAX * .9) else new |
else: # QSType.relay and any other |
new = _MAX if new > 0 else 0 |
def success(): |
""""""Success closure to update value."""""" |
self[qsid].value = new |
_LOGGER.debug(""set success %s=%s"", qsid, new) |
self._cb_value_changed(self, qsid, new) |
newqs = round(math.pow(round(new / _MAX * 100), 1 / self.dim_adj)) |
_LOGGER.debug(""%s hass=%s --> %s"", qsid, new, newqs) |
self._cb_set_qsvalue(qsid, newqs, success)" |
3875,"def update_devices(self, devices): |
""""""Update values from response of URL_DEVICES, callback if changed."""""" |
for qspacket in devices: |
try: |
qsid = qspacket[QS_ID] |
except KeyError: |
_LOGGER.debug(""Device without ID: %s"", qspacket) |
continue |
if qsid not in self: |
self[qsid] = QSDev(data=qspacket) |
dev = self[qsid] |
dev.data = qspacket |
# Decode value from QSUSB |
newqs = _legacy_status(qspacket[QS_VALUE]) |
if dev.is_dimmer: |
# Adjust dimmer exponentially to get a smoother effect |
newqs = min(round(math.pow(newqs, self.dim_adj)), 100) |
newin = round(newqs * _MAX / 100) |
if abs(dev.value - newin) > 1: # Significant change |
_LOGGER.debug(""%s qs=%s --> %s"", qsid, newqs, newin) |
dev.value = newin |
self._cb_value_changed(self, qsid, newin)" |
3876,"def geist_replay(wrapped, instance, args, kwargs): |
""""""Wraps a test of other function and injects a Geist GUI which will |
enable replay (set environment variable GEIST_REPLAY_MODE to 'record' to |
active record mode."""""" |
path_parts = [] |
file_parts = [] |
if hasattr(wrapped, '__module__'): |
module = wrapped.__module__ |
module_file = sys.modules[module].__file__ |
root, _file = os.path.split(module_file) |
path_parts.append(root) |
_file, _ = os.path.splitext(_file) |
file_parts.append(_file) |
if hasattr(wrapped, '__objclass__'): |
file_parts.append(wrapped.__objclass__.__name__) |
elif hasattr(wrapped, '__self__'): |
file_parts.append(wrapped.__self__.__class__.__name__) |
file_parts.append(wrapped.__name__ + '.log') |
path_parts.append('_'.join(file_parts)) |
filename = os.path.join(*path_parts) |
if is_in_record_mode(): |
platform_backend = get_platform_backend() |
backend = RecordingBackend( |
source_backend=platform_backend, |
recording_filename=filename |
) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.