greghesp / ha-bambulab

A Home Assistant Integration for Bambu Lab Printers
1.04k stars 92 forks source link

[Bug] Receiving a 'NoneType' TypeError. #630

Closed yaks11 closed 1 month ago

yaks11 commented 1 month ago

Describe the bug

I noticed that the following error will occur in Home Assistant log when I'm printing a 3D model.

2024-10-24 14:19:02.982 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback BambuDataUpdateCoordinator.event_handler_internal('event_print_error') (None) Traceback (most recent call last): File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/config/custom_components/bambu_lab/coordinator.py", line 109, in event_handler_internal self._update_print_error() File "/config/custom_components/bambu_lab/coordinator.py", line 194, in _update_print_error if 'Code' in device.print_error.error: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: argument of type 'NoneType' is not iterable

To Reproduce

I installed this Bambu Labs addon in Home Assistant and started to notice this error happening in the log file.

Expected Behaviour

Is there a way for the addon to handle this error or is there some sort of configuration I need to setup?

What device are you using?

P1S

Diagnostic Output

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2024.10.3",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.12.4",
    "docker": true,
    "arch": "x86_64",
    "timezone": "America/New_York",
    "os_name": "Linux",
    "os_version": "6.6.54-haos",
    "supervisor": "2024.10.3",
    "host_os": "Home Assistant OS 13.2",
    "docker_version": "27.2.0",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "eufy_security": {
      "documentation": "https://github.com/fuatakgun/eufy_security",
      "version": "8.0.4",
      "requirements": [
        "websocket-client==1.4.2",
        "aiortsp==1.3.7"
      ]
    },
    "hacs": {
      "documentation": "https://hacs.xyz/docs/configuration/start",
      "version": "2.0.1",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "robovac": {
      "documentation": "https://github.com/codefoodpixels/robovac",
      "version": "1.0.0",
      "requirements": []
    },
    "meross_lan": {
      "documentation": "https://github.com/krahabb/meross_lan",
      "version": "5.4.1-alpha.1",
      "requirements": []
    },
    "tplink_deco": {
      "documentation": "https://github.com/amosyuen/ha-tplink-deco",
      "version": "3.6.2",
      "requirements": [
        "pycryptodome>=3.12.0"
      ]
    },
    "smartthinq_sensors": {
      "documentation": "https://github.com/ollo69/ha-smartthinq-sensors",
      "version": "0.40.3",
      "requirements": [
        "pycountry>=23.12.11",
        "xmltodict>=0.13.0",
        "charset_normalizer>=3.2.0"
      ]
    },
    "webrtc": {
      "documentation": "https://github.com/AlexxIT/WebRTC",
      "version": "v3.6.0",
      "requirements": []
    },
    "nws_alerts": {
      "documentation": "https://github.com/finity69x2/nws_alerts/",
      "version": "5.0",
      "requirements": []
    },
    "bambu_lab": {
      "documentation": "https://github.com/greghesp/ha-bambulab",
      "version": "2.0.24",
      "requirements": [
        "httpx>=0.27.0"
      ]
    },
    "spook": {
      "documentation": "https://spook.boo",
      "version": "3.1.0",
      "requirements": []
    },
    "sonoff": {
      "documentation": "https://github.com/AlexxIT/SonoffLAN",
      "version": "3.8.1",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    }
  },
  "integration_manifest": {
    "domain": "bambu_lab",
    "name": "Bambu Lab",
    "codeowners": [
      "greghesp",
      "AdrianGarside"
    ],
    "config_flow": true,
    "dependencies": [
      "device_automation",
      "ffmpeg",
      "mqtt"
    ],
    "documentation": "https://github.com/greghesp/ha-bambulab",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/greghesp/ha-bambulab/issues",
    "requirements": [
      "httpx>=0.27.0"
    ],
    "ssdp": [
      {
        "st": "urn:bambulab-com:device:3dprinter:1"
      }
    ],
    "version": "2.0.24",
    "is_built_in": false
  },
  "setup_times": {},
  "data": {
    "config_entry": {
      "created_at": "2024-10-24T14:16:02.299850+00:00",
      "data": {
        "device_type": "P1S",
        "serial": "**REDACTED**"
      },
      "discovery_keys": {},
      "disabled_by": null,
      "domain": "bambu_lab",
      "entry_id": "01JAZE4TFVGC7ZX6JK17521MMQ",
      "minor_version": 1,
      "modified_at": "2024-10-24T18:36:30.387937+00:00",
      "options": {
        "region": "NorthAmerica",
        "email": "**REDACTED**",
        "username": "**REDACTED**",
        "name": "3D Printer - Music Room",
        "host": "192.168.223.195",
        "local_mqtt": false,
        "auth_token": "**REDACTED**",
        "access_code": "**REDACTED**",
        "usage_hours": 2.54
      },
      "pref_disable_new_entities": false,
      "pref_disable_polling": false,
      "source": "user",
      "title": "**REDACTED**",
      "unique_id": null,
      "version": 2
    },
    "push_all": {
      "upgrade_state": {
        "sequence_id": 0,
        "progress": "",
        "status": "",
        "consistency_request": false,
        "dis_state": 0,
        "err_code": 0,
        "force_upgrade": false,
        "message": "0%, 0B/s",
        "module": "",
        "new_version_state": 2,
        "cur_state_code": 1,
        "new_ver_list": []
      },
      "ipcam": {
        "ipcam_dev": "1",
        "ipcam_record": "enable",
        "timelapse": "disable",
        "resolution": "",
        "tutk_server": "enable",
        "mode_bits": 3
      },
      "upload": {
        "status": "idle",
        "progress": 0,
        "message": ""
      },
      "nozzle_temper": 219.40625,
      "nozzle_target_temper": 220,
      "bed_temper": 54.96875,
      "bed_target_temper": 55,
      "chamber_temper": 5,
      "mc_print_stage": "2",
      "heatbreak_fan_speed": "15",
      "cooling_fan_speed": "15",
      "big_fan1_speed": "12",
      "big_fan2_speed": "9",
      "mc_percent": 35,
      "mc_remaining_time": 17,
      "ams_status": 768,
      "ams_rfid_status": 2,
      "hw_switch_state": 1,
      "spd_mag": 100,
      "spd_lvl": 2,
      "print_error": 0,
      "lifecycle": "product",
      "wifi_signal": "-30dBm",
      "gcode_state": "RUNNING",
      "gcode_file_prepare_percent": "100",
      "queue_number": 0,
      "queue_total": 0,
      "queue_est": 0,
      "queue_sts": 0,
      "project_id": "150119973",
      "profile_id": "143640637",
      "task_id": "299551583",
      "subtask_id": "299551584",
      "subtask_name": "Tensioner Covers for X1 _ P1S",
      "gcode_file": "Tensioner Covers for X1 _ P1S.3mf",
      "stg": [
        2,
        14,
        1
      ],
      "stg_cur": 0,
      "print_type": "cloud",
      "home_flag": 24266039,
      "mc_print_line_number": "2549",
      "mc_print_sub_stage": 0,
      "sdcard": true,
      "force_upgrade": false,
      "mess_production_state": "active",
      "layer_num": 4,
      "total_layer_num": 25,
      "s_obj": [],
      "filam_bak": [],
      "fan_gear": 9883391,
      "nozzle_diameter": "0.4",
      "nozzle_type": "stainless_steel",
      "cali_version": 0,
      "hms": [],
      "online": {
        "ahb": false,
        "rfid": false,
        "version": 1716530177
      },
      "ams": {
        "ams": [
          {
            "id": "0",
            "humidity": "5",
            "temp": "0.0",
            "tray": [
              {
                "id": "0",
                "remain": -1,
                "k": 0.019999999552965164,
                "n": 1,
                "cali_idx": -1,
                "tag_uid": "FAD177DC00000100",
                "tray_id_name": "A00-W1",
                "tray_info_idx": "GFA00",
                "tray_type": "PLA",
                "tray_sub_brands": "PLA Basic",
                "tray_color": "FFFFFFFF",
                "tray_weight": "1000",
                "tray_diameter": "1.75",
                "tray_temp": "55",
                "tray_time": "8",
                "bed_temp_type": "0",
                "bed_temp": "0",
                "nozzle_temp_max": "230",
                "nozzle_temp_min": "190",
                "xcam_info": "34218813F401E8030000003F",
                "tray_uuid": "B915B14F2B5D4DE39B7E2371CDA2BCBB",
                "ctype": 0,
                "cols": [
                  "FFFFFFFF"
                ]
              },
              {
                "id": "1",
                "remain": -1,
                "k": 0.019999999552965164,
                "n": 1,
                "cali_idx": -1,
                "tag_uid": "0000000000000000",
                "tray_id_name": "",
                "tray_info_idx": "GFL99",
                "tray_type": "PLA",
                "tray_sub_brands": "",
                "tray_color": "84620DFF",
                "tray_weight": "0",
                "tray_diameter": "0.00",
                "tray_temp": "0",
                "tray_time": "0",
                "bed_temp_type": "0",
                "bed_temp": "0",
                "nozzle_temp_max": "240",
                "nozzle_temp_min": "190",
                "xcam_info": "000000000000000000000000",
                "tray_uuid": "00000000000000000000000000000000",
                "ctype": 0,
                "cols": [
                  "84620DFF"
                ]
              },
              {
                "id": "2",
                "remain": -1,
                "k": 0.019999999552965164,
                "n": 1,
                "cali_idx": -1,
                "tag_uid": "5A7833B900000100",
                "tray_id_name": "A00-K0",
                "tray_info_idx": "GFA00",
                "tray_type": "PLA",
                "tray_sub_brands": "PLA Basic",
                "tray_color": "000000FF",
                "tray_weight": "1000",
                "tray_diameter": "1.75",
                "tray_temp": "55",
                "tray_time": "8",
                "bed_temp_type": "0",
                "bed_temp": "0",
                "nozzle_temp_max": "230",
                "nozzle_temp_min": "190",
                "xcam_info": "803E803EE803E803CDCC4C3F",
                "tray_uuid": "3ED85D58C21F408F9DE98FDF4BF54A84",
                "ctype": 0,
                "cols": [
                  "000000FF"
                ]
              },
              {
                "id": "3",
                "remain": -1,
                "k": 0.019999999552965164,
                "n": 1,
                "cali_idx": -1,
                "tag_uid": "7A2F69AC00000100",
                "tray_id_name": "G02-K0",
                "tray_info_idx": "GFG02",
                "tray_type": "PETG",
                "tray_sub_brands": "PETG HF",
                "tray_color": "000000FF",
                "tray_weight": "1000",
                "tray_diameter": "1.75",
                "tray_temp": "65",
                "tray_time": "8",
                "bed_temp_type": "0",
                "bed_temp": "0",
                "nozzle_temp_max": "260",
                "nozzle_temp_min": "230",
                "xcam_info": "8813A438F40158020000803F",
                "tray_uuid": "FA800BB0CDA64E3FAD7772B86AABAD59",
                "ctype": 0,
                "cols": [
                  "000000FF"
                ]
              }
            ]
          }
        ],
        "ams_exist_bits": "1",
        "tray_exist_bits": "f",
        "tray_is_bbl_bits": "f",
        "tray_tar": "0",
        "tray_now": "0",
        "tray_pre": "0",
        "tray_read_done_bits": "f",
        "tray_reading_bits": "0",
        "version": 35,
        "insert_flag": true,
        "power_on_flag": false
      },
      "vt_tray": {
        "id": "254",
        "tag_uid": "0000000000000000",
        "tray_id_name": "",
        "tray_info_idx": "",
        "tray_type": "",
        "tray_sub_brands": "",
        "tray_color": "00000000",
        "tray_weight": "0",
        "tray_diameter": "0.00",
        "tray_temp": "0",
        "tray_time": "0",
        "bed_temp_type": "0",
        "bed_temp": "0",
        "nozzle_temp_max": "0",
        "nozzle_temp_min": "0",
        "xcam_info": "000000000000000000000000",
        "tray_uuid": "00000000000000000000000000000000",
        "remain": 0,
        "k": 0.019999999552965164,
        "n": 1,
        "cali_idx": -1
      },
      "lights_report": [
        {
          "node": "chamber_light",
          "mode": "on"
        }
      ],
      "command": "push_status",
      "msg": 0,
      "sequence_id": "1424"
    },
    "get_version": {
      "command": "get_version",
      "sequence_id": "20027",
      "module": [
        {
          "name": "ota",
          "project_name": "C12",
          "sw_ver": "01.06.01.02",
          "hw_ver": "OTA",
          "sn": "**REDACTED**",
          "flag": 3
        },
        {
          "name": "esp32",
          "project_name": "C12",
          "sw_ver": "01.08.27.62",
          "hw_ver": "AP04",
          "sn": "**REDACTED**",
          "flag": 0
        },
        {
          "name": "mc",
          "project_name": "P1",
          "sw_ver": "00.00.26.61",
          "loader_ver": "00.00.00.28",
          "hw_ver": "MC07",
          "sn": "**REDACTED**",
          "flag": 0
        },
        {
          "name": "th",
          "project_name": "P1",
          "sw_ver": "00.00.09.95",
          "loader_ver": "00.00.00.14",
          "hw_ver": "TH09",
          "sn": "**REDACTED**",
          "flag": 0
        },
        {
          "name": "ams/0",
          "project_name": "",
          "sw_ver": "00.00.06.44",
          "loader_ver": "00.00.00.00",
          "ota_ver": "00.00.00.00",
          "hw_ver": "AMS08",
          "sn": "**REDACTED**",
          "flag": 0
        }
      ],
      "result": "success",
      "reason": ""
    }
  }
}

Log Extracts

2024-10-24 14:19:02.982 ERROR (MainThread) [homeassistant] Error doing job: Exception in callback BambuDataUpdateCoordinator.event_handler_internal('event_print_error') (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/bambu_lab/coordinator.py", line 109, in event_handler_internal
    self._update_print_error()
  File "/config/custom_components/bambu_lab/coordinator.py", line 194, in _update_print_error
    if 'Code' in device.print_error.error:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable

Other Information

No response

AdrianGarside commented 1 month ago

That's... odd. That variable is always initiailized to None when there's no errors. If you're seeing that error, everyone should be.

AdrianGarside commented 1 month ago

Aha, this happens when the HMS printe error clears. This code was recently fixed for another error it had but the fixed code now fails a different way because it was never valid in the first place to try and use the error list when it's empty (None).

AdrianGarside commented 1 month ago

Fixed with #634

AdrianGarside commented 1 month ago

Fixed in https://github.com/greghesp/ha-bambulab/releases/tag/v2.0.25-dev3