mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-01 19:38:21 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c364b716f4 | ||
|
|
48e1782484 | ||
|
|
ff30675a25 | ||
|
|
7b3965ff4b | ||
|
|
2ebdfabd9b |
@@ -79,4 +79,4 @@ Platform ID list for GOG Galaxy 2.0 Integrations
|
|||||||
| psvita | Playstation Vita |
|
| psvita | Playstation Vita |
|
||||||
| nds | Nintendo DS |
|
| nds | Nintendo DS |
|
||||||
| 3ds | Nintendo 3DS |
|
| 3ds | Nintendo 3DS |
|
||||||
|
| pathofexile | Path of Exile |
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="galaxy.plugin.api",
|
name="galaxy.plugin.api",
|
||||||
version="0.39",
|
version="0.40",
|
||||||
description="GOG Galaxy Integrations Python API",
|
description="GOG Galaxy Integrations Python API",
|
||||||
author='Galaxy team',
|
author='Galaxy team',
|
||||||
author_email='galaxy@gog.com',
|
author_email='galaxy@gog.com',
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ class Platform(Enum):
|
|||||||
PlayStationVita = "psvita"
|
PlayStationVita = "psvita"
|
||||||
NintendoDs = "nds"
|
NintendoDs = "nds"
|
||||||
Nintendo3Ds = "3ds"
|
Nintendo3Ds = "3ds"
|
||||||
|
PathOfExile = "pathofexile"
|
||||||
|
|
||||||
class Feature(Enum):
|
class Feature(Enum):
|
||||||
"""Possible features that can be implemented by an integration.
|
"""Possible features that can be implemented by an integration.
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ class Server():
|
|||||||
data = data.strip()
|
data = data.strip()
|
||||||
logging.debug("Received %d bytes of data", len(data))
|
logging.debug("Received %d bytes of data", len(data))
|
||||||
self._handle_input(data)
|
self._handle_input(data)
|
||||||
|
await asyncio.sleep(0) # To not starve task queue
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._active = False
|
self._active = False
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class Plugin:
|
|||||||
|
|
||||||
self._feature_methods = OrderedDict()
|
self._feature_methods = OrderedDict()
|
||||||
self._active = True
|
self._active = True
|
||||||
|
self._pass_control_task = None
|
||||||
|
|
||||||
self._reader, self._writer = reader, writer
|
self._reader, self._writer = reader, writer
|
||||||
self._handshake_token = handshake_token
|
self._handshake_token = handshake_token
|
||||||
@@ -210,15 +211,17 @@ class Plugin:
|
|||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
"""Plugin's main coroutine."""
|
"""Plugin's main coroutine."""
|
||||||
async def pass_control():
|
await self._server.run()
|
||||||
while self._active:
|
if self._pass_control_task is not None:
|
||||||
try:
|
await self._pass_control_task
|
||||||
self.tick()
|
|
||||||
except Exception:
|
|
||||||
logging.exception("Unexpected exception raised in plugin tick")
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
await asyncio.gather(pass_control(), self._server.run())
|
async def _pass_control(self):
|
||||||
|
while self._active:
|
||||||
|
try:
|
||||||
|
self.tick()
|
||||||
|
except Exception:
|
||||||
|
logging.exception("Unexpected exception raised in plugin tick")
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
def _shutdown(self):
|
def _shutdown(self):
|
||||||
logging.info("Shutting down")
|
logging.info("Shutting down")
|
||||||
@@ -236,6 +239,7 @@ class Plugin:
|
|||||||
def _initialize_cache(self, data: Dict):
|
def _initialize_cache(self, data: Dict):
|
||||||
self._persistent_cache = data
|
self._persistent_cache = data
|
||||||
self.handshake_complete()
|
self.handshake_complete()
|
||||||
|
self._pass_control_task = asyncio.create_task(self._pass_control())
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _ping():
|
def _ping():
|
||||||
|
|||||||
@@ -204,5 +204,5 @@ class GameTime():
|
|||||||
:param last_time_played: last time the game was played (**unix timestamp**)
|
:param last_time_played: last time the game was played (**unix timestamp**)
|
||||||
"""
|
"""
|
||||||
game_id: str
|
game_id: str
|
||||||
time_played: int
|
time_played: Optional[int]
|
||||||
last_played_time: int
|
last_played_time: Optional[int]
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ def test_success(plugin, read, write):
|
|||||||
read.side_effect = [json.dumps(request).encode() + b"\n", b""]
|
read.side_effect = [json.dumps(request).encode() + b"\n", b""]
|
||||||
plugin.get_game_times.coro.return_value = [
|
plugin.get_game_times.coro.return_value = [
|
||||||
GameTime("3", 60, 1549550504),
|
GameTime("3", 60, 1549550504),
|
||||||
GameTime("5", 10, 1549550502)
|
GameTime("5", 10, None),
|
||||||
|
GameTime("7", None, 1549550502),
|
||||||
]
|
]
|
||||||
asyncio.run(plugin.run())
|
asyncio.run(plugin.run())
|
||||||
plugin.get_game_times.assert_called_with()
|
plugin.get_game_times.assert_called_with()
|
||||||
@@ -35,7 +36,10 @@ def test_success(plugin, read, write):
|
|||||||
{
|
{
|
||||||
"game_id": "5",
|
"game_id": "5",
|
||||||
"time_played": 10,
|
"time_played": 10,
|
||||||
"last_played_time": 1549550502
|
},
|
||||||
|
{
|
||||||
|
"game_id": "7",
|
||||||
|
"last_played_time": 1549550502
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,18 @@ def test_ping(plugin, read, write):
|
|||||||
"result": None
|
"result": None
|
||||||
}
|
}
|
||||||
|
|
||||||
def test_tick(plugin, read):
|
def test_tick_before_handshake(plugin, read):
|
||||||
read.side_effect = [b""]
|
read.side_effect = [b""]
|
||||||
asyncio.run(plugin.run())
|
asyncio.run(plugin.run())
|
||||||
|
plugin.tick.assert_not_called()
|
||||||
|
|
||||||
|
def test_tick_after_handshake(plugin, read):
|
||||||
|
request = {
|
||||||
|
"jsonrpc": "2.0",
|
||||||
|
"id": "6",
|
||||||
|
"method": "initialize_cache",
|
||||||
|
"params": {"data": {}}
|
||||||
|
}
|
||||||
|
read.side_effect = [json.dumps(request).encode() + b"\n", b""]
|
||||||
|
asyncio.run(plugin.run())
|
||||||
plugin.tick.assert_called_with()
|
plugin.tick.assert_called_with()
|
||||||
|
|||||||
Reference in New Issue
Block a user