Ejemplo n.º 1
0
def process_octoprint_status(printer: Printer, status: Dict) -> None:
    octoprint_settings = status.get('octoprint_settings')
    if octoprint_settings:
        cache.printer_settings_set(printer.id, settings_dict(octoprint_settings))

    # for backward compatibility
    if status.get('octoprint_data'):
        if 'octoprint_temperatures' in status:
            status['octoprint_data']['temperatures'] = status['octoprint_temperatures']

    if status.get('octoprint_data', {}).get('_ts'):   # data format for plugin 1.6.0 and higher
        cache.printer_status_set(printer.id, json.dumps(status.get('octoprint_data', {})), ex=STATUS_TTL_SECONDS)
    else:
        octoprint_data: Dict = dict()
        set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'state')
        set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'progress')
        set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'file_metadata')
        set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'currentZ')
        set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'job')
        set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'temperatures')
        cache.printer_status_set(printer.id, octoprint_data, ex=STATUS_TTL_SECONDS)

    if status.get('current_print_ts'):
        process_octoprint_status_with_ts(status, printer)

    channels.send_status_to_web(printer.id)

    temps = status.get('octoprint_data', {}).get('temperatures', None)
    if temps:
        process_heater_temps(printer, temps)
def process_octoprint_status(printer, status):
    octoprint_settings = status.get('octoprint_settings')
    if octoprint_settings:
        cache.printer_settings_set(printer.id, settings_dict(octoprint_settings))

    octoprint_data = dict()
    set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'state')
    set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'progress')
    set_as_str_if_present(octoprint_data, status, 'octoprint_temperatures', 'temperatures')
    cache.printer_status_set(printer.id, octoprint_data, ex=STATUS_TTL_SECONDS)

    if status.get('current_print_ts'):
        process_octoprint_status_with_ts(status, printer)

    channels.send_status_to_web(printer.id)
def process_octoprint_status(printer: Printer, status: Dict) -> None:
    octoprint_settings = status.get('octoprint_settings')
    if octoprint_settings:
        cache.printer_settings_set(printer.id, settings_dict(octoprint_settings))

    octoprint_data: Dict = dict()
    set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'state')
    set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'progress')
    set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'file_metadata')
    set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'currentZ')
    set_as_str_if_present(octoprint_data, status.get('octoprint_data', {}), 'job')
    set_as_str_if_present(octoprint_data, status, 'octoprint_temperatures', 'temperatures')
    cache.printer_status_set(printer.id, octoprint_data, ex=STATUS_TTL_SECONDS)

    if status.get('current_print_ts'):
        process_octoprint_status_with_ts(status, printer)

    channels.send_status_to_web(printer.id)

    temps = status.get('octoprint_temperatures', None)
    if temps:
        process_heater_temps(printer, temps)