Skip to content

Commit

Permalink
SW-2301 fix errors (#1816)
Browse files Browse the repository at this point in the history
- include alpha release of iobeam
- fix error
- reduce logging
  • Loading branch information
Josef-MrBeam committed Oct 4, 2023
1 parent fb183e8 commit 81240e8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
15 changes: 9 additions & 6 deletions octoprint_mrbeam/analytics/usage_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _event_start(self, event, payload):
self._load_usage_data()
self.start_time_total = self._usage_data[self.TOTAL_KEY][self.JOB_TIME_KEY]
self.start_time_prefilter = self.get_prefilter_usage()
self.start_time_carbon_filter = self.get_carbon_filter_usage
self.start_time_carbon_filter = self.get_carbon_filter_usage()
self.start_time_laser_head = self._usage_data[self.LASER_HEAD_KEY][
self._laser_head_serial
][self.JOB_TIME_KEY]
Expand Down Expand Up @@ -347,9 +347,7 @@ def _set_job_time(self, component, job_time):
element = element[key]
element[self.JOB_TIME_KEY] = job_time
self._logger.debug(
"Set job time for component {} to {} - {}".format(
component, job_time, self._usage_data
)
"Set job time for component {} to {}".format(component, job_time)
)

def _get_job_time(self, usage_data):
Expand All @@ -360,9 +358,12 @@ def _get_job_time(self, usage_data):
usage_data: Usage data to get the job time from
Returns:
int: job time in seconds
int: job time in seconds, -1 if it could not be found
"""
return usage_data.get(self.JOB_TIME_KEY, None)
if self.JOB_TIME_KEY not in usage_data:
self._logger.info("No job time found in usage data, returning -1")
return -1
return usage_data.get(self.JOB_TIME_KEY, -1)

def _get_airfilter_serial(self):
"""
Expand Down Expand Up @@ -872,6 +873,8 @@ def _migrate_old_airfilter_structure_to_new(self):
self._usage_data.pop(self.CARBON_FILTER_KEY, None)
self._usage_data.pop(self.PREFILTER_KEY, None)

self._write_usage_data()

self._logger.info(
"Migrated AF2 filter stage job time (pre:{} carbon:{}) to serial: {}".format(
prefilter, carbon_filter, serial
Expand Down
2 changes: 1 addition & 1 deletion octoprint_mrbeam/dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
iobeam==1.2.2
iobeam==1.3.0a0
mrb-hw-info==1.0.0
mrbeam-ledstrips==1.0.0
mrbeamdoc==1.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,6 @@ $(function () {
}
if ("maintenance_information" in data) {
const maintenanceInformation = data.maintenance_information;
console.log(
"Maintenance information received",
maintenanceInformation
);
if (self.needsGantryMaintenance()) {
self.gantryUsage(maintenanceInformation.gantryUsage);
} else {
Expand Down
39 changes: 39 additions & 0 deletions tests/analytics/test_usage_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,45 @@ def test_load_load_with_file(usage_handler):
) # there is curretnly no get_compressor_usage() method


def test_load_with_empty_file(mrbeam_plugin):
usage_file = """
"""

def settings_get(key, default=None, **kwargs):
if key == ["analytics", "usage_filename"]:
return "test.yaml"
elif key == ["analytics", "folder"]:
return "analytics"
elif key == ["analytics", "usage_backup_filename"]:
return "backup.yaml"

with patch("__builtin__.open", mock_open(read_data=usage_file)), patch(
"octoprint_mrbeam.analytics.usage_handler.UsageHandler._write_usage_data",
return_value=True,
), patch("os.path.isfile", lambda x: True):
mrbeam_plugin.laserhead_handler.current_laserhead_max_dust_factor = 3.0
mrbeam_plugin.laserhead_handler.get_current_used_lh_data = MagicMock(
return_value={"serial": LASERHEAD_SERIAL}
)
mrbeam_plugin.airfilter = MagicMock(serial="dummy_serial")
mrbeam_plugin._settings.get = MagicMock(
side_effect=settings_get
) # return_value="test.yaml")
usage_handler = UsageHandler(mrbeam_plugin)
usage_handler._on_mrbeam_plugin_initialized(None, None)

# Assert
assert usage_handler.get_gantry_usage() == 0
assert usage_handler.get_laser_head_usage() == 0
assert usage_handler.get_prefilter_usage() == -1
assert usage_handler.get_carbon_filter_usage() == -1
assert usage_handler.get_total_usage() == 0
assert usage_handler.get_total_jobs() == 0
assert (
usage_handler._usage_data["compressor"]["job_time"] == 0
) # there is curretnly no get_compressor_usage() method


@pytest.mark.parametrize(
"heavy_duty_filter, expected_lifespan",
[
Expand Down

0 comments on commit 81240e8

Please sign in to comment.