Skip to content

Commit

Permalink
Add gcode_file & subtask_name string sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianGarside committed Sep 7, 2023
1 parent 850a25d commit ee815b7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions custom_components/bambu_lab/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,20 @@ class BambuLabBinarySensorEntityDescription(BinarySensorEntityDescription, Bambu
value_fn=lambda self: self.coordinator.get_model().ams.tray_now + 1,
exists_fn=lambda coordinator: coordinator.get_model().supports_feature(Features.AMS)
),
BambuLabSensorEntityDescription(
key="gcode_file",
translation_key="gcode_file",
icon="mdi:file",
available_fn=lambda self: self.coordinator.get_model().info.gcode_file != "",
value_fn=lambda self: self.coordinator.get_model().info.gcode_file
),
BambuLabSensorEntityDescription(
key="subtask_name",
translation_key="subtask_name",
icon="mdi:file",
available_fn=lambda self: self.coordinator.get_model().info.subtask_name != "",
value_fn=lambda self: self.coordinator.get_model().info.subtask_name
),
)

VIRTUAL_TRAY_SENSORS: tuple[BambuLabSensorEntityDescription, ...] = (
Expand Down
4 changes: 4 additions & 0 deletions custom_components/bambu_lab/pybambu/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ def __init__(self, client, device_type, serial):
self.hw_ver = "unknown"
self.sw_ver = "unknown"
self.gcode_state = "unknown"
self.gcode_file = ""
self.subtask_name = ""
self.serial = serial
self.remaining_time = 0
self.end_time = 0
Expand Down Expand Up @@ -317,6 +319,8 @@ def print_update(self, data):
self.wifi_signal = int(data.get("wifi_signal", str(self.wifi_signal)).replace("dBm", ""))
self.print_percentage = data.get("mc_percent", self.print_percentage)
self.gcode_state = data.get("gcode_state", self.gcode_state)
self.gcode_file = data.get("gcode_file", self.gcode_file)
self.subtask_name = data.get("subtask_name", self.subtask_name)
self.remaining_time = data.get("mc_remaining_time", self.remaining_time)
if data.get("gcode_start_time") is not None:
self.start_time = start_time(int(data.get("gcode_start_time")))
Expand Down
6 changes: 6 additions & 0 deletions custom_components/bambu_lab/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@
"prepare": "Prepare"
}
},
"gcode_file": {
"name": "Gcode filename"
},
"subtask_name": {
"name": "Task name"
},
"start_time": {
"name": "Start time"
},
Expand Down

0 comments on commit ee815b7

Please sign in to comment.