async def get_game_time(self, game_id: str, context: None) -> GameTime: return GameTime( game_id=game_id, time_played=None, last_played_time=None, )
async def get_game_time(self, game_id, context=None): if game_id in self.game_times: game_time = self.game_times[game_id] return GameTime(game_id, game_time[0] // 60, game_time[1])
async def get_game_time(self, game_id: str, context: Any) -> GameTime: try: return self.__gametime_tracker.get_tracked_time(game_id) except GameNotTrackedException: return GameTime(game_id, 0, 0)
def tick(self): if self.game_running and self.running_game is not None: self.game_times[self.running_game][0] += self.TICK_TIME self.game_times[self.running_game][1] += self.TICK_TIME self.update_game_time(GameTime(self.running_game, self.game_times[self.running_game][0] // 60, self.game_times[self.running_game][1]))
def update_time(self, game): new_game_times = get_game_times() game_time = new_game_times[game.game_id] self.game_times[game.game_id] = game_time self.update_game_time(GameTime(game.game_id, game_time[0] // 60, game_time[1]))
(120, 1551288960), # missing in new 'last_played' response (5, 1551288965) # previously missing ] LASTPLAYED_GAMES = { MASTER_TITLE_IDS[0]: NEW_BACKEND_GAME_USAGE_RESPONSES[0][1], MASTER_TITLE_IDS[1]: NEW_BACKEND_GAME_USAGE_RESPONSES[1][1], # MASTER_TITLE_IDS[2] previously existed, now missing MASTER_TITLE_IDS[3]: NEW_BACKEND_GAME_USAGE_RESPONSES[3][1] } GAME_TIMES = [ GameTime(OFFER_IDS[i], *BACKEND_GAME_USAGE_RESPONSES[i]) for i in range(len(OFFER_IDS)) ] @pytest.mark.asyncio async def test_not_authenticated(plugin, http_client): http_client.is_authenticated.return_value = False with pytest.raises(AuthenticationRequired): await plugin.prepare_game_times_context([]) BACKEND_LASTPLAYED_RESPONSE = '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <lastPlayedGames> <userId>1008620950926</userId> <lastPlayed>
game_times_dict = {} for game in self_games: entry = {} id = str(game[1]) entry["name"] = game[2] entry["time_played"] = 0 entry["last_time_played"] = 0 game_times_dict[id] = entry print(game_times_dict) with open(game_times_path, "w") as game_times_file: json.dump(game_times_dict, game_times_file, indent=4) # Once the file exists read it and return the game times game_times = {} with open(game_times_path, "r") as game_times_file: parsed_game_times_file = json.load(game_times_file) print(parsed_game_times_file) for entry in parsed_game_times_file: game_id = entry time_played = int(parsed_game_times_file.get(entry).get("time_played")) last_time_played = int( parsed_game_times_file.get(entry).get("last_time_played")) print(game_id) print(time_played) print(last_time_played) game_times[game_id] = GameTime(game_id, time_played, last_time_played) print(game_times)
async def get_game_time(self, game_id, context=None): game_times = self.game_times game_time = int(game_times[game_id][0]) game_time /= 60 return GameTime(game_id, game_time, game_times[game_id][1])
async def test_get_game_time_success(plugin, read, write): plugin.prepare_game_times_context.return_value = async_return_value("abc") request = { "jsonrpc": "2.0", "id": "3", "method": "start_game_times_import", "params": { "game_ids": ["3", "5", "7"] } } read.side_effect = [ async_return_value(create_message(request)), async_return_value(b"", 10) ] plugin.get_game_time.side_effect = [ async_return_value(GameTime("3", 60, 1549550504)), async_return_value(GameTime("5", 10, None)), async_return_value(GameTime("7", None, 1549550502)), ] await plugin.run() plugin.get_game_time.assert_has_calls([ call("3", "abc"), call("5", "abc"), call("7", "abc"), ]) plugin.game_times_import_complete.assert_called_once_with() assert get_messages(write) == [{ "jsonrpc": "2.0", "id": "3", "result": None }, { "jsonrpc": "2.0", "method": "game_time_import_success", "params": { "game_time": { "game_id": "3", "last_played_time": 1549550504, "time_played": 60 } } }, { "jsonrpc": "2.0", "method": "game_time_import_success", "params": { "game_time": { "game_id": "5", "time_played": 10 } } }, { "jsonrpc": "2.0", "method": "game_time_import_success", "params": { "game_time": { "game_id": "7", "last_played_time": 1549550502 } } }, { "jsonrpc": "2.0", "method": "game_times_import_finished", "params": None }]
async def get_game_time(self, game_id: str, context: Dict[int, int]) -> GameTime: time_played = self._times_cache.get(game_id, {}).get('time_played') last_played = self._times_cache.get(game_id, {}).get('last_played') if last_played == 86400: last_played = None return GameTime(game_id, time_played, last_played)