simplyprint: remove keepalive
This will be replaced by a custom ping timer to the backend. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
2e3188a48b
commit
f8d15d3baa
|
@ -50,12 +50,10 @@ COMPONENT_VERSION = "0.0.1"
|
||||||
SP_VERSION = "0.1"
|
SP_VERSION = "0.1"
|
||||||
TEST_ENDPOINT = f"wss://testws.simplyprint.io/{SP_VERSION}/p"
|
TEST_ENDPOINT = f"wss://testws.simplyprint.io/{SP_VERSION}/p"
|
||||||
PROD_ENDPOINT = f"wss://ws.simplyprint.io/{SP_VERSION}/p"
|
PROD_ENDPOINT = f"wss://ws.simplyprint.io/{SP_VERSION}/p"
|
||||||
KEEPALIVE_TIME = 96.0
|
|
||||||
# TODO: Increase this time to something greater, perhaps 30 minutes
|
# TODO: Increase this time to something greater, perhaps 30 minutes
|
||||||
CONNECTION_ERROR_LOG_TIME = 60.
|
CONNECTION_ERROR_LOG_TIME = 60.
|
||||||
PRE_SETUP_EVENTS = [
|
PRE_SETUP_EVENTS = [
|
||||||
"connection", "state_change", "shutdown", "machine_data", "keepalive",
|
"connection", "state_change", "shutdown", "machine_data", "firmware"
|
||||||
"firmware"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
class SimplyPrint(Subscribable):
|
class SimplyPrint(Subscribable):
|
||||||
|
@ -94,7 +92,6 @@ class SimplyPrint(Subscribable):
|
||||||
self.heaters: Dict[str, str] = {}
|
self.heaters: Dict[str, str] = {}
|
||||||
self.missed_job_events: List[Dict[str, Any]] = []
|
self.missed_job_events: List[Dict[str, Any]] = []
|
||||||
self.announce_mutex = asyncio.Lock()
|
self.announce_mutex = asyncio.Lock()
|
||||||
self.keepalive_hdl: Optional[asyncio.TimerHandle] = None
|
|
||||||
self.connection_task: Optional[asyncio.Task] = None
|
self.connection_task: Optional[asyncio.Task] = None
|
||||||
self.reconnect_delay: float = 1.
|
self.reconnect_delay: float = 1.
|
||||||
self.reconnect_token: Optional[str] = None
|
self.reconnect_token: Optional[str] = None
|
||||||
|
@ -256,9 +253,6 @@ class SimplyPrint(Subscribable):
|
||||||
logging.info(msg)
|
logging.info(msg)
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.ws = None
|
self.ws = None
|
||||||
if self.keepalive_hdl is not None:
|
|
||||||
self.keepalive_hdl.cancel()
|
|
||||||
self.keepalive_hdl = None
|
|
||||||
break
|
break
|
||||||
|
|
||||||
def _on_ws_ping(self, data: bytes = b"") -> None:
|
def _on_ws_ping(self, data: bytes = b"") -> None:
|
||||||
|
@ -266,7 +260,6 @@ class SimplyPrint(Subscribable):
|
||||||
|
|
||||||
def _process_message(self, msg: str) -> None:
|
def _process_message(self, msg: str) -> None:
|
||||||
self._logger.info(f"received: {msg}")
|
self._logger.info(f"received: {msg}")
|
||||||
self._reset_keepalive()
|
|
||||||
try:
|
try:
|
||||||
packet: Dict[str, Any] = json.loads(msg)
|
packet: Dict[str, Any] = json.loads(msg)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
|
@ -1069,19 +1062,8 @@ class SimplyPrint(Subscribable):
|
||||||
self._logger.info(f"sent: {packet}")
|
self._logger.info(f"sent: {packet}")
|
||||||
else:
|
else:
|
||||||
self._logger.info("sent: webcam stream")
|
self._logger.info("sent: webcam stream")
|
||||||
self._reset_keepalive()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _reset_keepalive(self):
|
|
||||||
if self.keepalive_hdl is not None:
|
|
||||||
self.keepalive_hdl.cancel()
|
|
||||||
self.keepalive_hdl = self.eventloop.delay_callback(
|
|
||||||
KEEPALIVE_TIME, self._do_keepalive)
|
|
||||||
|
|
||||||
def _do_keepalive(self):
|
|
||||||
self.keepalive_hdl = None
|
|
||||||
self.send_sp("keepalive", None)
|
|
||||||
|
|
||||||
def _get_object_diff(
|
def _get_object_diff(
|
||||||
self, new_obj: Dict[str, Any], cached_obj: Dict[str, Any]
|
self, new_obj: Dict[str, Any], cached_obj: Dict[str, Any]
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
|
@ -1104,9 +1086,6 @@ class SimplyPrint(Subscribable):
|
||||||
self.is_closing = True
|
self.is_closing = True
|
||||||
if self.ws is not None:
|
if self.ws is not None:
|
||||||
self.ws.close(1001, "Client Shutdown")
|
self.ws.close(1001, "Client Shutdown")
|
||||||
if self.keepalive_hdl is not None:
|
|
||||||
self.keepalive_hdl.cancel()
|
|
||||||
self.keepalive_hdl = None
|
|
||||||
if (
|
if (
|
||||||
self.connection_task is not None and
|
self.connection_task is not None and
|
||||||
not self.connection_task.done()
|
not self.connection_task.done()
|
||||||
|
|
Loading…
Reference in New Issue