text stringlengths 0 828 |
|---|
else: |
alarmDevice = ALARM.create_alarm(panelJson, self) |
self._devices['0'] = alarmDevice |
# Now we will handle the power switches |
switches = self.get_power_switches() |
_LOGGER.debug( |
'Get active the power switches in get_devices: %s', switches) |
for deviceJson in switches: |
# Attempt to reuse an existing device |
device = self._devices.get(deviceJson['name']) |
# No existing device, create a new one |
if device: |
device.update(deviceJson) |
else: |
device = newDevice(deviceJson, self) |
if not device: |
_LOGGER.info('Device is unknown') |
continue |
self._devices[device.device_id] = device |
if generic_type: |
devices = [] |
for device in self._devices.values(): |
if (device.type is not None and |
device.type in generic_type[0]): |
devices.append(device) |
return devices |
return list(self._devices.values())" |
307,"def parse_from_dict(json_dict): |
"""""" |
Given a Unified Uploader message, parse the contents and return a |
MarketHistoryList instance. |
:param dict json_dict: A Unified Uploader message as a dict. |
:rtype: MarketOrderList |
:returns: An instance of MarketOrderList, containing the orders |
within. |
"""""" |
history_columns = json_dict['columns'] |
history_list = MarketHistoryList( |
upload_keys=json_dict['uploadKeys'], |
history_generator=json_dict['generator'], |
) |
for rowset in json_dict['rowsets']: |
generated_at = parse_datetime(rowset['generatedAt']) |
region_id = rowset['regionID'] |
type_id = rowset['typeID'] |
history_list.set_empty_region(region_id, type_id, generated_at) |
for row in rowset['rows']: |
history_kwargs = _columns_to_kwargs( |
SPEC_TO_KWARG_CONVERSION, history_columns, row) |
historical_date = parse_datetime(history_kwargs['historical_date']) |
history_kwargs.update({ |
'type_id': type_id, |
'region_id': region_id, |
'historical_date': historical_date, |
'generated_at': generated_at, |
}) |
history_list.add_entry(MarketHistoryEntry(**history_kwargs)) |
return history_list" |
308,"def encode_to_json(history_list): |
"""""" |
Encodes this MarketHistoryList instance to a JSON string. |
:param MarketHistoryList history_list: The history instance to serialize. |
:rtype: str |
"""""" |
rowsets = [] |
for items_in_region_list in history_list._history.values(): |
region_id = items_in_region_list.region_id |
type_id = items_in_region_list.type_id |
generated_at = gen_iso_datetime_str(items_in_region_list.generated_at) |
rows = [] |
for entry in items_in_region_list.entries: |
historical_date = gen_iso_datetime_str(entry.historical_date) |
# The order in which these values are added is crucial. It must |
# match STANDARD_ENCODED_COLUMNS. |
rows.append([ |
historical_date, |
entry.num_orders, |
entry.total_quantity, |
entry.low_price, |
entry.high_price, |
entry.average_price, |
]) |
rowsets.append(dict( |
generatedAt = generated_at, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.