mattcar15 / bambu-connect

Connect to the stats, controls, and camera of your bambu printer
Other
47 stars 8 forks source link

After P1S Update: unexpected keyword argument 'resolution' #6

Open lixxbox opened 8 months ago

lixxbox commented 8 months ago

I opened a new issue because the error seems to be a different one.

Today I updated my P1S to the new version today. Since then, I get the following error:

Executing dump_info.
Exception in thread Thread-1 (_thread_main):
Traceback (most recent call last):
  File "C:\Python311\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Python311\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3033, in _packet_handle       
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3327, in _handle_publish      
    self._handle_on_message(message)
  File "C:\Python311\Lib\site-packages\paho\mqtt\client.py", line 3570, in _handle_on_message   
    on_message(self, self._userdata, message)
  File "C:\Python311\Lib\site-packages\bambu_connect\WatchClient.py", line 54, in on_message    
    self.printerStatus = PrinterStatus(**self.values)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\bambu_connect\utils\models.py", line 201, in __init__    
    self.ipcam = IPCam(**data["ipcam"]) if "ipcam" in data else None
                 ^^^^^^^^^^^^^^^^^^^^^^
TypeError: IPCam.__init__() got an unexpected keyword argument 'resolution'

There seem to be some new key/value pairs. Can't tell you, which ones, exactly. Some I've found: ipcam.resolution, nozzle_type, filam_bak, nozzle_diameter, upgrade_state.cur_state_code. I also don't know if there are differences between X/P/A-series...

{
  "print": {
    "ams": {
      "ams": [
        {
          "humidity": "5",
          "id": "0",
          "temp": "0.0",
          "tray": [
            {
              "bed_temp": "0",
              "bed_temp_type": "0",
              "id": "0",
              "k": 0.019999999552965164,
              "n": 1,
              "nozzle_temp_max": "280",
              "nozzle_temp_min": "240",
              "remain": -1,
              "tag_uid": "0000000000000000",
              "tray_color": "898989FF",
              "tray_diameter": "0.00",
              "tray_id_name": "",
              "tray_info_idx": "GFB98",
              "tray_sub_brands": "",
              "tray_temp": "0",
              "tray_time": "0",
              "tray_type": "ASA",
              "tray_uuid": "00000000000000000000000000000000",
              "tray_weight": "0",
              "xcam_info": "000000000000000000000000"
            },
            {
              "bed_temp": "0",
              "bed_temp_type": "0",
              "id": "1",
              "k": 0.019999999552965164,
              "n": 1,
              "nozzle_temp_max": "280",
              "nozzle_temp_min": "240",
              "remain": -1,
              "tag_uid": "0000000000000000",
              "tray_color": "F72323FF",
              "tray_diameter": "0.00",
              "tray_id_name": "",
              "tray_info_idx": "GFB99",
              "tray_sub_brands": "",
              "tray_temp": "0",
              "tray_time": "0",
              "tray_type": "ABS",
              "tray_uuid": "00000000000000000000000000000000",
              "tray_weight": "0",
              "xcam_info": "000000000000000000000000"
            },
            {
              "bed_temp": "0",
              "bed_temp_type": "0",
              "id": "2",
              "k": 0.019999999552965164,
              "n": 1,
              "nozzle_temp_max": "280",
              "nozzle_temp_min": "240",
              "remain": -1,
              "tag_uid": "0000000000000000",
              "tray_color": "161616FF",
              "tray_diameter": "0.00",
              "tray_id_name": "",
              "tray_info_idx": "GFB99",
              "tray_sub_brands": "",
              "tray_temp": "0",
              "tray_time": "0",
              "tray_type": "ABS",
              "tray_uuid": "00000000000000000000000000000000",
              "tray_weight": "0",
              "xcam_info": "000000000000000000000000"
            },
            {
              "bed_temp": "0",
              "bed_temp_type": "0",
              "id": "3",
              "k": 0.019999999552965164,
              "n": 1,
              "nozzle_temp_max": "280",
              "nozzle_temp_min": "240",
              "remain": -1,
              "tag_uid": "0000000000000000",
              "tray_color": "FFFFFFFF",
              "tray_diameter": "0.00",
              "tray_id_name": "",
              "tray_info_idx": "GFB99",
              "tray_sub_brands": "",
              "tray_temp": "0",
              "tray_time": "0",
              "tray_type": "ABS",
              "tray_uuid": "00000000000000000000000000000000",
              "tray_weight": "0",
              "xcam_info": "000000000000000000000000"
            }
          ]
        }
      ],
      "ams_exist_bits": "1",
      "insert_flag": false,
      "power_on_flag": false,
      "tray_exist_bits": "f",
      "tray_is_bbl_bits": "f",
      "tray_now": "255",
      "tray_pre": "255",
      "tray_read_done_bits": "f",
      "tray_reading_bits": "0",
      "tray_tar": "255",
      "version": 3
    },
    "ams_rfid_status": 0,
    "ams_status": 0,
    "bed_target_temper": 0,
    "bed_temper": 17.84375,
    "big_fan1_speed": "0",
    "big_fan2_speed": "0",
    "chamber_temper": 5,
    "command": "push_status",
    "cooling_fan_speed": "0",
    "fan_gear": 0,
    "filam_bak": [],
    "force_upgrade": false,
    "gcode_file": "",
    "gcode_file_prepare_percent": "0",
    "gcode_state": "IDLE",
    "heatbreak_fan_speed": "0",
    "hms": [],
    "home_flag": 2114952,
    "hw_switch_state": 0,
    "ipcam": {
      "ipcam_dev": "1",
      "ipcam_record": "enable",
      "mode_bits": 3,
      "resolution": "",
      "timelapse": "disable"
    },
    "layer_num": 0,
    "lifecycle": "product",
    "lights_report": [
      {
        "mode": "off",
        "node": "chamber_light"
      }
    ],
    "mc_percent": 0,
    "mc_print_line_number": "0",
    "mc_print_stage": "1",
    "mc_print_sub_stage": 0,
    "mc_remaining_time": 0,
    "mess_production_state": "active",
    "msg": 1,
    "nozzle_diameter": "0.4",
    "nozzle_target_temper": 0,
    "nozzle_temper": 22.21875,
    "nozzle_type": "stainless_steel",
    "online": {
      "ahb": false,
      "rfid": false,
      "version": 733385994
    },
    "print_error": 0,
    "print_type": "idle",
    "profile_id": "0",
    "project_id": "0",
    "queue_est": 0,
    "queue_number": 0,
    "queue_sts": 0,
    "queue_total": 0,
    "s_obj": [],
    "sdcard": true,
    "sequence_id": "79",
    "spd_lvl": 2,
    "spd_mag": 100,
    "stg": [],
    "stg_cur": 0,
    "subtask_id": "0",
    "subtask_name": "",
    "task_id": "0",
    "total_layer_num": 0,
    "upgrade_state": {
      "consistency_request": false,
      "cur_state_code": 0,
      "dis_state": 0,
      "err_code": 0,
      "force_upgrade": false,
      "message": "0%, 0B/s",
      "module": "",
      "new_ver_list": [],
      "new_version_state": 2,
      "progress": "",
      "sequence_id": 0,
      "status": ""
    },
    "upload": {
      "message": "",
      "progress": 0,
      "status": "idle"
    },
    "vt_tray": {
      "bed_temp": "0",
      "bed_temp_type": "0",
      "id": "254",
      "k": 0.019999999552965164,
      "n": 1,
      "nozzle_temp_max": "0",
      "nozzle_temp_min": "0",
      "remain": 0,
      "tag_uid": "0000000000000000",
      "tray_color": "00000000",
      "tray_diameter": "0.00",
      "tray_id_name": "",
      "tray_info_idx": "",
      "tray_sub_brands": "",
      "tray_temp": "0",
      "tray_time": "0",
      "tray_type": "",
      "tray_uuid": "00000000000000000000000000000000",
      "tray_weight": "0",
      "xcam_info": "000000000000000000000000"
    },
    "wifi_signal": "-74dBm"
  }
}
evnchn commented 6 months ago

Can be hot-patched by editing the models.py which was throwing an error as follows:

@dataclass
class IPCam:
    ipcam_dev: Optional[str] = None
    ipcam_record: Optional[str] = None
    timelapse: Optional[str] = None
    mode_bits: Optional[int] = None
    resolution: Optional[int] = None # // evnchn

@dataclass
class LightsReport:
    node: Optional[str] = None
    mode: Optional[str] = None

@dataclass
class UpgradeState:
    sequence_id: Optional[int] = None
    progress: Optional[str] = None
    status: Optional[str] = None
    consistency_request: Optional[bool] = None
    dis_state: Optional[int] = None
    err_code: Optional[int] = None
    force_upgrade: Optional[bool] = None
    message: Optional[str] = None
    module: Optional[str] = None
    new_version_state: Optional[int] = None
    new_ver_list: Optional[List[Any]] = None
    cur_state_code: Optional[int] = None # // evnchn

Personally, hardcoding the fields may not be a good idea if it does not fail gracefully. I shall look into more graceful ways of handling discrepancies caused by version updates, and if I do come up with a solution, I shall pull request.

Mainly the issue now is the camera stream is not working

z00kiii commented 2 months ago

having the same issure here.

edited models.py like this:

self.ipcam = None # IPCam(**data["ipcam"]) if "ipcam" in data else None // z00kiii
self.vt_tray = None #  VTTray(**data["vt_tray"]) if "vt_tray" in data else None // z00kiii
self.lights_report = [LightsReport(**lr) for lr in data.get("lights_report", [])]
self.upgrade_state = None # UpgradeState(**data["upgrade_state"]) if "upgrade_state" in data else None //z00kiii

dirty as well but @evnchn's approach did not work for me, as there occurred other problems with IPCam, VTTray and upgrade State