From 522eb40808e410db8d7302d93f6996df729932a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 8 Jun 2014 16:52:28 +0200 Subject: [PATCH] Documented SockJS interface, deprecated /api/state --- docs/api/datamodel.rst | 348 ++++++++++++++++++ docs/api/fileops.rst | 141 +------ docs/api/index.rst | 2 + docs/api/job.rst | 84 +---- docs/api/printer.rst | 109 +----- docs/api/sockjs.rst | 114 ++++++ docs/index.rst | 8 +- src/octoprint/printer.py | 20 +- src/octoprint/server/api/__init__.py | 6 +- src/octoprint/server/api/job.py | 2 +- src/octoprint/server/api/printer.py | 5 +- .../static/js/app/viewmodels/printerstate.js | 2 +- .../static/js/app/viewmodels/temperature.js | 2 +- .../static/js/app/viewmodels/terminal.js | 2 +- 14 files changed, 490 insertions(+), 355 deletions(-) create mode 100644 docs/api/datamodel.rst create mode 100644 docs/api/sockjs.rst diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst new file mode 100644 index 00000000..76fc003c --- /dev/null +++ b/docs/api/datamodel.rst @@ -0,0 +1,348 @@ +.. _sec-api-datamodel: + +***************** +Common data model +***************** + +.. contents:: + +.. _sec-api-datamodel-printer: + +Printer related +=============== + +.. _sec-api-datamodel-printer-state: + +Printer State +------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``text`` + - 1 + - String + - A textual representation of the current state of the printer, e.g. "Operational" or "Printing" + * - ``flags`` + - 1 + - Printer state flags + - A couple of boolean printer state flags + * - ``flags.operational`` + - 1 + - Boolean + - ``true`` if the printer is operational, ``false`` otherwise + * - ``flags.paused`` + - 1 + - Boolean + - ``true`` if the printer is currently paused, ``false`` otherwise + * - ``flags.printing`` + - 1 + - Boolean + - ``true`` if the printer is currently printing, ``false`` otherwise + * - ``flags.sdReady`` + - 1 + - Boolean + - ``true`` if the printer's SD card is available and initialized, ``false`` otherwise. This is redundant information + to :ref:`the SD State `. + * - ``flags.error`` + - 1 + - Boolean + - ``true`` if an unrecoverable error occurred, ``false`` otherwise + * - ``flags.ready`` + - 1 + - Boolean + - ``true`` if the printer is operational and no data is currently being streamed to SD, so ready to receive instructions + * - ``flags.closedOrError`` + - 1 + - Boolean + - ``true`` if the printer is disconnected (possibly due to an error), ``false`` otherwise + +.. _sec-api-datamodel-printer-tempdata: + +Temperature Data +---------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``actual`` + - 1 + - Number + - Current temperature + * - ``target`` + - 1 + - Number + - Target temperature, may be ``null`` if no target temperature is set. + * - ``offset`` + - 0..1 + - Number + - Currently configured temperature offset to apply, will be left out for historic temperature information. + +.. _sec-api-datamodel-printer-temphistory: + +Historic Temperature Data Point +------------------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``time`` + - 1 + - Unix Timestamp + - Timestamp of this data point + * - ``tool{n}`` + - 0..* + - :ref:`Temperature Data ` + - Temperature stats for tool *n*. Enumeration starts at 0 for the first tool. Not included if querying only + bed state. + * - ``bed`` + - 0..* + - :ref:`Temperature Data ` + - Temperature stats for the printer's heated bed. Not included if querying only tool state. + +.. _sec-api-datamodel-printer-tempoffset: + +Temperature offset +------------------ + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``tool{n}`` + - 0..1 + - Number + - Temperature offset for tool *n*. Enumeration starts at 0 for the first tool. + * - ``bed`` + - 0..1 + - Number + - Temperature offset for the printer's heated bed. + + +.. _sec-api-datamodel-jobs: + +Job related +=========== + +.. _sec-api-datamodel-jobs-job: + +Job information +--------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``file`` + - 1 + - :ref:`File information (abridged) ` + - The file that is the target of the current print job + * - ``estimatedPrintTime`` + - 0..1 + - Integer + - The estimated print time for the file, in seconds. + * - ``filament`` + - 0..1 + - Object + - Information regarding the estimated filament usage of the print job + * - ``filament.length`` + - 0..1 + - Integer + - Length of filament used, in mm + * - ``filament.volume`` + - 0..1 + - Float + - Volume of filament used, in cm³ + +.. _sec-api-datamodel-jobs-progress: + +Progress information +-------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``completion`` + - 1 + - Float + - Percentage of completion of the current print job + * - ``filepos`` + - 1 + - Integer + - Current position in the file being printed, in bytes from the beginning + * - ``printTime`` + - 1 + - Integer + - Time already spent printing, in seconds + * - ``printTimeLeft`` + - 1 + - Integer + - Estimate of time left to print, in seconds + +.. _sec-api-datamodel-files: + +File related +============ + +.. _sec-api-datamodel-files-file: + +File information +---------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``name`` + - 1 + - String + - The name of the file + * - ``size`` + - 0..1 + - Number + - The size of the file in bytes. Only available for ``local`` files. + * - ``date`` + - 0..1 + - Unix timestamp + - The timestamp when this file was uploaded. Only available for ``local`` files. + * - ``origin`` + - 1 + - String, either ``local`` or ``sdcard`` + - The origin of the file, ``local`` when stored in OctoPrint's ``uploads`` folder, ``sdcard`` when stored on the + printer's SD card (if available) + * - ``refs`` + - 0..1 + - :ref:`sec-api-datamodel-files-ref` + - References relevant to this file, left out in abridged version + * - ``gcodeAnalysis`` + - 0..1 + - :ref:`GCODE analysis information ` + - Information from the analysis of the GCODE file, if available. Left out in abridged version. + * - ``prints`` + - 0..1 + - :ref:`Print history ` + - Information regarding prints of this file, if available. Left out in abridged version. + +.. _sec-api-datamodel-files-gcodeanalysis: + +GCODE analysis information +-------------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``estimatedPrintTime`` + - 0..1 + - Integer + - The estimated print time of the file, in seconds + * - ``filament`` + - 0..1 + - Object + - The estimated usage of filament + * - ``filament.length`` + - 0..1 + - Integer + - The length of filament used, in mm + * - ``filament.volume`` + - 0..1 + - Float + - The volume of filament used, in cm³ + + +.. _sec-api-datamodel-files-prints: + +Print history +------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``failure`` + - 1 + - Number + - The number of failed prints on record for the file + * - ``success`` + - 1 + - Number + - The number of successful prints on record for the file + * - ``last`` + - 0..1 + - Object + - Information regarding the last print on record for the file + * - ``last.date`` + - 1 + - Unix timestamp + - Timestamp when this file was printed last + * - ``last.success`` + - 1 + - Boolean + - Whether the last print on record was a success (``true``) or not (``false``) + +.. _sec-api-datamodel-files-ref: + +References +---------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``resource`` + - 1 + - URL + - The resource that represents the file (e.g. for issuing commands to or for deleting) + * - ``download`` + - 0..1 + - URL + - The download URL for the file + * - ``model`` + - 0..1 + - URL + - The model from which this file was generated (e.g. an STL, currently not used) + diff --git a/docs/api/fileops.rst b/docs/api/fileops.rst index ce8ae277..baf3440d 100644 --- a/docs/api/fileops.rst +++ b/docs/api/fileops.rst @@ -240,7 +240,7 @@ Retrieve a specific file's information If the file is unknown, a :http:statuscode:`404` is returned. - On success, a :http:statuscode:`200` is returned, with a :ref:`file information item ` + On success, a :http:statuscode:`200` is returned, with a :ref:`file information item ` as the response body. **Example** @@ -383,7 +383,7 @@ Retrieve response - Description * - ``files`` - 0..* - - Array of :ref:`File information items ` + - Array of :ref:`File information items ` - The list of requested files. Might be an empty list if no files are available * - ``free`` - 0..1 @@ -411,12 +411,12 @@ Upload response contain the ``local`` property. If uploaded to SD card, this will contain both ``local`` and ``sdcard`` properties. * - ``files.local`` - 1 - - :ref:`sec-api-fileops-datamodel-fileinfo` + - :ref:`sec-api-datamodel-files-file` - The information regarding the file that was just uploaded to the local storage (only the fields ``name``, ``origin`` and ``refs`` will be set). * - ``files.sdcard`` - 0..1 - - :ref:`sec-api-fileops-datamodel-fileinfo` + - :ref:`sec-api-datamodel-files-file` - The information regarding the file that was just uploaded to the printer's SD card (only the fields ``name``, ``origin`` and ``refs`` will be set). * - ``done`` @@ -426,136 +426,3 @@ Upload response to perform a slicing step (``false``). Clients may use this information to direct progress displays related to the upload. -.. _sec-api-fileops-datamodel-fileinfo: - -File information ----------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``name`` - - 1 - - String - - The name of the file - * - ``size`` - - 0..1 - - Number - - The size of the file in bytes. Only available for ``local`` files. - * - ``date`` - - 0..1 - - Unix timestamp - - The timestamp when this file was uploaded. Only available for ``local`` files. - * - ``origin`` - - 1 - - String, either ``local`` or ``sdcard`` - - The origin of the file, ``local`` when stored in OctoPrint's ``uploads`` folder, ``sdcard`` when stored on the - printer's SD card (if available) - * - ``refs`` - - 0..1 - - :ref:`sec-api-fileops-datamodel-ref` - - References relevant to this file - * - ``gcodeAnalysis`` - - 0..1 - - :ref:`GCODE analysis information ` - - Information from the analysis of the GCODE file, if available. - * - ``prints`` - - 0..1 - - :ref:`Print information ` - - Information regarding prints of this file, if available. - -.. _sec-api-fileops-datamodel-gcodeanalysis: - -GCODE analysis information --------------------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``estimatedPrintTime`` - - 0..1 - - Integer - - The estimated print time of the file, in seconds - * - ``filament`` - - 0..1 - - Object - - The estimated usage of filament - * - ``filament.length`` - - 0..1 - - Integer - - The length of filament used, in mm - * - ``filament.volume`` - - 0..1 - - Float - - The volume of filament used, in cm³ - - -.. _sec-api-fileops-datamodel-prints: - -Print information ------------------ - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``failure`` - - 1 - - Number - - The number of failed prints on record for the file - * - ``success`` - - 1 - - Number - - The number of successful prints on record for the file - * - ``last`` - - 0..1 - - Object - - Information regarding the last print on record for the file - * - ``last.date`` - - 1 - - Unix timestamp - - Timestamp when this file was printed last - * - ``last.success`` - - 1 - - Boolean - - Whether the last print on record was a success (``true``) or not (``false``) - -.. _sec-api-fileops-datamodel-ref: - -References ----------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``resource`` - - 1 - - URL - - The resource that represents the file (e.g. for issuing commands to or for deleting) - * - ``download`` - - 0..1 - - URL - - The download URL for the file - * - ``model`` - - 0..1 - - URL - - The model from which this file was generated (e.g. an STL, currently not used) diff --git a/docs/api/index.rst b/docs/api/index.rst index 7d296a1b..c5033f31 100644 --- a/docs/api/index.rst +++ b/docs/api/index.rst @@ -13,3 +13,5 @@ API Documentation printer.rst job.rst logs.rst + sockjs.rst + datamodel.rst diff --git a/docs/api/job.rst b/docs/api/job.rst index 04c48b86..3bcc1fde 100644 --- a/docs/api/job.rst +++ b/docs/api/job.rst @@ -174,90 +174,10 @@ Job information response - Description * - ``job`` - 1 - - :ref:`sec-api-job-datamodel-job` + - :ref:`sec-api-datamodel-jobs-job` - Information regarding the target of the current print job * - ``progress`` - 1 - - :ref:`sec-api-job-datamodel-progress` + - :ref:`sec-api-datamodel-jobs-progress` - Information regarding the progress of the current print job -.. _sec-api-job-datamodel-job: - -Job information ---------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``file`` - - 1 - - Object - - The file that is the target of the current print job - * - ``file.name`` - - 1 - - String - - The file's name - * - ``file.origin`` - - 1 - - String, either ``local`` or ``sdcard`` - - The file's origin, either ``local`` or ``sdcard`` - * - ``file.size`` - - 0..1 - - Integer - - The file's size, in bytes. Only available for files stored locally. - * - ``file.date`` - - 0..1 - - Unix timestamp - - The file's upload date. Only available for files stored locally. - * - ``estimatedPrintTime`` - - 0..1 - - Integer - - The estimated print time for the file, in seconds. - * - ``filament`` - - 0..1 - - Object - - Information regarding the estimated filament usage of the print job - * - ``filament.length`` - - 0..1 - - Integer - - Length of filament used, in mm - * - ``filament.volume`` - - 0..1 - - Float - - Volume of filament used, in cm³ - -.. _sec-api-job-datamodel-progress: - -Progress information --------------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``completion`` - - 1 - - Float - - Percentage of completion of the current print job - * - ``filepos`` - - 1 - - Integer - - Current position in the file being printed, in bytes from the beginning - * - ``printTime`` - - 1 - - Integer - - Time already spent printing, in seconds - * - ``printTimeLeft`` - - 1 - - Integer - - Estimate of time left to print, in seconds - diff --git a/docs/api/printer.rst b/docs/api/printer.rst index 19eb9ec6..f80ff6a8 100644 --- a/docs/api/printer.rst +++ b/docs/api/printer.rst @@ -801,71 +801,18 @@ Temperature State - Description * - ``tool{n}`` - 0..* - - :ref:`Temperature Data ` + - :ref:`Temperature Data ` - Current temperature stats for tool *n*. Enumeration starts at 0 for the first tool. Not included if querying only bed state. * - ``bed`` - 0..1 - - :ref:`Temperature Data ` + - :ref:`Temperature Data ` - Current temperature stats for the printer's heated bed. Not included if querying only tool state. * - ``history`` - 0..1 - - List of :ref:`Historic Temperature Datapoint ` + - List of :ref:`Historic Temperature Datapoint ` - Temperature history -.. _sec-api-printer-datamodel-temphistory: - -Historic Temperature Data Point -------------------------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``time`` - - 1 - - Unix Timestamp - - Timestamp of this data point - * - ``tool{n}`` - - 0..* - - :ref:`Temperature Data ` - - Temperature stats for tool *n*. Enumeration starts at 0 for the first tool. Not included if querying only - bed state. - * - ``bed`` - - 0..* - - :ref:`Temperature Data ` - - Temperature stats for the printer's heated bed. Not included if querying only tool state. - -.. _sec-api-printer-datamodel-tempdata: - -Temperature Data ----------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``actual`` - - 1 - - Number - - Current temperature - * - ``target`` - - 1 - - Number - - Target temperature, may be ``null`` if no target temperature is set. - * - ``offset`` - - 0..1 - - Number - - Currently configured temperature offset to apply, will be left out for historic temperature information. - .. _sec-api-printer-datamodel-sdstate: SD State @@ -884,53 +831,3 @@ SD State - Boolean - Whether the SD card has been initialized (``true``) or not (``false``). -.. _sec-api-printer-datamodel-printerstate: - -Printer State -------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``text`` - - 1 - - String - - A textual representation of the current state of the printer, e.g. "Operational" or "Printing" - * - ``flags`` - - 1 - - Printer state flags - - A couple of boolean printer state flags - * - ``flags.operational`` - - 1 - - Boolean - - ``true`` if the printer is operational, ``false`` otherwise - * - ``flags.paused`` - - 1 - - Boolean - - ``true`` if the printer is currently paused, ``false`` otherwise - * - ``flags.printing`` - - 1 - - Boolean - - ``true`` if the printer is currently printing, ``false`` otherwise - * - ``flags.sdReady`` - - 1 - - Boolean - - ``true`` if the printer's SD card is available and initialized, ``false`` otherwise. This is redundant information - to :ref:`the SD State `. - * - ``flags.error`` - - 1 - - Boolean - - ``true`` if an unrecoverable error occurred, ``false`` otherwise - * - ``flags.ready`` - - 1 - - Boolean - - ``true`` if the printer is operational and no data is currently being streamed to SD, so ready to receive instructions - * - ``flags.closedOrError`` - - 1 - - Boolean - - ``true`` if the printer is disconnected (possibly due to an error), ``false`` otherwise diff --git a/docs/api/sockjs.rst b/docs/api/sockjs.rst new file mode 100644 index 00000000..fab32b0f --- /dev/null +++ b/docs/api/sockjs.rst @@ -0,0 +1,114 @@ +.. _sec-api-push: + +************ +Push updates +************ + +.. warning:: + + The interface documented here is the status quo that might be changed while the interfaces are streamlined for + a more general consumption. If you happen to want to develop against it, you should drop me an email to make sure I can give you a heads-up when + something changes. + +.. contents:: + +To enable real time information exchange between client and server, OctoPrint uses +`SockJS `_ to push +status updates, temperature changes etc to connected web interface instances. + +Each pushed message consists of a simple JSON object that follows this basic structure: + +.. sourcecode:: javascript + + { + "": + } + +``type`` indicates the type of message being pushed to the client, the attached ``payload`` is message specific. The +following message types are currently available for usage by 3rd party clients: + + * ``current``: Rate limited general state update, payload contains information about the printer's state, job progress, + accumulated temperature points and log lines since last update. OctoPrint will send these updates when new information + is available, but not more often than twice per second in order to not flood the client with messages (e.g. + during printing). See :ref:`the payload data model `. + * ``history``: Current state, temperature and log history, sent upon initial connect to get the client up to date. Same + payload data model as ``current``, see :ref:`below `. + * ``event``: Events triggered within OctoPrint, such as e.g. ``PrintFailed`` or ``MovieRenderDone``. Payload is the event + type and payload, see :ref:`below `. Sent when an event is triggered internally. + +Clients must ignore any unknown messages. + +The data model of the attached payloads is described further below. + +.. _sec-api-push-datamodel: + +Datamodel +========= + +.. _sec-api-push-datamodel-currentandhistory: + +``current`` and ``history`` payload +----------------------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``state`` + - 1 + - :ref:`State information ` + - Information about the current machine state + * - ``job`` + - 1 + - :ref:`Job information ` + - Information about the currently active print job + * - ``progress`` + - 1 + - :ref:`Progress information ` + - Information about the current print/streaming progress + * - ``currentZ`` + - 1 + - Float + - Current height of the Z-Axis (= current height of model) during printing from a local file + * - ``offsets`` + - 0..1 + - :ref:`Temperature offsets ` + - Currently configured temperature offsets + * - ``temps`` + - 0..* + - List of :ref:`Temperature Data Points ` + - Temperature data points for plotting + * - ``logs`` + - 0..* + - List of String + - Lines for the serial communication log (send/receive) + * - ``messages`` + - 0..* + - List of String + - Lines for the serial communication log (special messages) + +.. _sec-api-push-datamodel-event: + +``event`` payload +----------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``type`` + - 1 + - String + - Name of the event + * - ``payload`` + - 1 + - Object + - Payload associated with the event diff --git a/docs/index.rst b/docs/index.rst index 87f940b4..d563a99a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,8 +1,3 @@ -.. OctoPrint documentation master file, created by - sphinx-quickstart on Mon Dec 02 17:08:50 2013. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - ##################################### Welcome to OctoPrint's documentation! ##################################### @@ -11,7 +6,7 @@ Welcome to OctoPrint's documentation! :alt: The OctoPrint Logo :align: right -This is a work in progress. The goal is to document OctoPrint's REST API, event system, configuration etc in way that +This is a work in progress. The goal is to document OctoPrint's REST API, event system, configuration etc in a way that allows different documentation per development branch in Git, which so far did not scale well with the Github-Wiki-based approach. @@ -22,4 +17,3 @@ Contents :maxdepth: 2 api/index.rst - diff --git a/src/octoprint/printer.py b/src/octoprint/printer.py index e6abdb2d..f2582382 100644 --- a/src/octoprint/printer.py +++ b/src/octoprint/printer.py @@ -87,7 +87,7 @@ class Printer(): addMessageCallback=self._sendAddMessageCallbacks ) self._stateMonitor.reset( - state={"state": None, "stateString": self.getStateString(), "flags": self._getStateFlags()}, + state={"text": self.getStateString(), "flags": self._getStateFlags()}, jobData={ "file": { "name": None, @@ -323,7 +323,7 @@ class Printer(): def _setState(self, state): self._state = state - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) + self._stateMonitor.setState({"text": self.getStateString(), "flags": self._getStateFlags()}) def _addLog(self, log): self._log.append(log) @@ -410,9 +410,9 @@ class Printer(): try: data = self._stateMonitor.getCurrentData() data.update({ - "tempHistory": list(self._temps), - "logHistory": list(self._log), - "messageHistory": list(self._messages) + "temps": list(self._temps), + "logs": list(self._log), + "messages": list(self._messages) }) callback.sendHistoryData(data) except Exception, err: @@ -492,7 +492,7 @@ class Printer(): self._setCurrentZ(newZ) def mcSdStateChange(self, sdReady): - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) + self._stateMonitor.setState({"text": self.getStateString(), "flags": self._getStateFlags()}) def mcSdFiles(self, files): eventManager().fire(Events.UPDATED_FILES, {"type": "gcode"}) @@ -500,21 +500,21 @@ class Printer(): def mcFileSelected(self, filename, filesize, sd): self._setJobData(filename, filesize, sd) - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) + self._stateMonitor.setState({"text": self.getStateString(), "flags": self._getStateFlags()}) if self._printAfterSelect: self.startPrint() def mcPrintjobDone(self): self._setProgressData(1.0, self._selectedFile["filesize"], self._comm.getPrintTime(), 0) - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) + self._stateMonitor.setState({"text": self.getStateString(), "flags": self._getStateFlags()}) def mcFileTransferStarted(self, filename, filesize): self._sdStreaming = True self._setJobData(filename, filesize, True) self._setProgressData(0.0, 0, 0, None) - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) + self._stateMonitor.setState({"text": self.getStateString(), "flags": self._getStateFlags()}) def mcFileTransferDone(self, filename): self._sdStreaming = False @@ -526,7 +526,7 @@ class Printer(): self._setCurrentZ(None) self._setJobData(None, None, None) self._setProgressData(None, None, None, None) - self._stateMonitor.setState({"state": self._state, "stateString": self.getStateString(), "flags": self._getStateFlags()}) + self._stateMonitor.setState({"text": self.getStateString(), "flags": self._getStateFlags()}) def mcReceivedRegisteredMessage(self, command, output): self._sendFeedbackCommandOutput(command, output) diff --git a/src/octoprint/server/api/__init__.py b/src/octoprint/server/api/__init__.py index 37292e33..3c92eb70 100644 --- a/src/octoprint/server/api/__init__.py +++ b/src/octoprint/server/api/__init__.py @@ -132,11 +132,7 @@ def firstRunSetup(): @api.route("/state", methods=["GET"]) @restricted_access def apiPrinterState(): - currentData = octoprint.server.printer.getCurrentData() - currentData.update({ - "temperatures": octoprint.server.printer.getCurrentTemperatures() - }) - return jsonify(currentData) + return make_response(("/api/state has been deprecated, use /api/printer instead", 405, [])) #~~ system control diff --git a/src/octoprint/server/api/job.py b/src/octoprint/server/api/job.py index ac8f4e54..3ee86a1a 100644 --- a/src/octoprint/server/api/job.py +++ b/src/octoprint/server/api/job.py @@ -53,5 +53,5 @@ def jobState(): return jsonify({ "job": currentData["job"], "progress": currentData["progress"], - "state": currentData["state"]["stateString"] + "state": currentData["state"]["text"] }) \ No newline at end of file diff --git a/src/octoprint/server/api/printer.py b/src/octoprint/server/api/printer.py index 87d71717..a4229729 100644 --- a/src/octoprint/server/api/printer.py +++ b/src/octoprint/server/api/printer.py @@ -38,10 +38,7 @@ def printerState(): # add state information if not "state" in excludes: state = printer.getCurrentData()["state"] - result.update({"state": { - "text": state["stateString"], - "flags": state["flags"] - }}) + result.update({"state": state}) return jsonify(result) diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 1ba8cdc2..bc1dda81 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -101,7 +101,7 @@ function PrinterStateViewModel(loginStateViewModel) { } self._processStateData = function(data) { - self.stateString(data.stateString); + self.stateString(data.text); self.isErrorOrClosed(data.flags.closedOrError); self.isOperational(data.flags.operational); self.isPaused(data.flags.paused); diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index ae529c8f..4ee2768e 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -118,7 +118,7 @@ function TemperatureViewModel(loginStateViewModel, settingsViewModel) { self.fromHistoryData = function(data) { self._processStateData(data.state); - self._processTemperatureHistoryData(data.tempHistory); + self._processTemperatureHistoryData(data.temps); self._processOffsetData(data.offsets); }; diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index ad8240f3..edf5841c 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -37,7 +37,7 @@ function TerminalViewModel(loginStateViewModel, settingsViewModel) { self.fromHistoryData = function(data) { self._processStateData(data.state); - self._processHistoryLogData(data.logHistory); + self._processHistoryLogData(data.logs); }; self._processCurrentLogData = function(data) {